Fixed
Status Update
Comments
xo...@google.com <xo...@google.com>
vi...@google.com <vi...@google.com>
tn...@google.com <tn...@google.com> #2
EDIT: meant TypedArray#recycle
and not TypedArray#release
va...@gmail.com <va...@gmail.com> #3
Lint should show a warning in this case, as implements AutoClosable
and the use of TypedArray#close()
require API level 31. Consequently the IDE should also not suggest the refactor to try with resources unless minSdk
is at least 31.
Maybe the issue is that api-versions.xml
(from platforms/android-33/data/api-versions.xml
) only mention implements AutoClosable
, and not the close()
method
<class name="android/content/res/TypedArray" since="1">
<extends name="java/lang/Object"/>
<implements name="java/lang/AutoCloseable" since="31"/>
<method name="getBoolean(IZ)Z"/>
<method name="getChangingConfigurations()I" since="21"/>
<method name="getColor(II)I"/>
<method name="getColorStateList(I)Landroid/content/res/ColorStateList;"/>
<method name="getDimension(IF)F"/>
<method name="getDimensionPixelOffset(II)I"/>
<method name="getDimensionPixelSize(II)I"/>
<method name="getDrawable(I)Landroid/graphics/drawable/Drawable;"/>
<method name="getFloat(IF)F"/>
<method name="getFont(I)Landroid/graphics/Typeface;" since="26"/>
<method name="getFraction(IIIF)F"/>
<method name="getIndex(I)I"/>
<method name="getIndexCount()I"/>
<method name="getInt(II)I"/>
<method name="getInteger(II)I"/>
<method name="getLayoutDimension(II)I" since="3"/>
<method name="getLayoutDimension(ILjava/lang/String;)I"/>
<method name="getNonResourceString(I)Ljava/lang/String;"/>
<method name="getPositionDescription()Ljava/lang/String;"/>
<method name="getResourceId(II)I"/>
<method name="getResources()Landroid/content/res/Resources;"/>
<method name="getSourceResourceId(II)I" since="29"/>
<method name="getString(I)Ljava/lang/String;"/>
<method name="getText(I)Ljava/lang/CharSequence;"/>
<method name="getTextArray(I)[Ljava/lang/CharSequence;"/>
<method name="getType(I)I" since="21"/>
<method name="getValue(ILandroid/util/TypedValue;)Z"/>
<method name="hasValue(I)Z"/>
<method name="hasValueOrEmpty(I)Z" since="22"/>
<method name="length()I"/>
<method name="peekValue(I)Landroid/util/TypedValue;"/>
<method name="recycle()V"/>
</class>
Opened TypedArray#close()
to TypedArray#recycle()
, to make try with resources for TypedArray
supported on all API levels.
Description
The following code:
get's flagged by Lint:
It probably only sees the
>= 30
check but not the parent if statement that checks for>= 28
.AGP: 7.2.2