Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating compileSdkVersion to 34 causes deceprecation errors for newInstance() #346

Closed
ahinton-league opened this issue Aug 23, 2023 · 2 comments

Comments

@ahinton-league
Copy link

The following code generated by showkase has a deprecation warning when we update our Android SDK version to 34

public fun Showkase.getMetadata(): ShowkaseElementsMetadata {
    try {
      val showkaseComponentProvider =
          Class.forName("REDACTED").newInstance() // deprecated!!!
          as ShowkaseProvider
      return showkaseComponentProvider.metadata()
    } catch(exception: ClassNotFoundException) {
      error("The class wasn't generated correctly. Make sure that you have setup Showkase correctly by following the steps here - https://github.com/airbnb/Showkase#Installation.")
    }
}

Added in API level 1 Deprecated in API level 34
public T newInstance ()
This method was deprecated in API level 34. This method propagates any exception thrown by the nullary constructor, including a checked exception. Use of this method effectively bypasses the compile-time exception checking that would otherwise be performed by the compiler. The Constructor.newInstance method avoids this problem by wrapping any exception thrown by the constructor in a (checked) InvocationTargetException .
The call
clazz.newInstance()

can be replaced by
clazz.getDeclaredConstructor().newInstance()

@ahinton-league
Copy link
Author

ahinton-league commented Aug 23, 2023

Our development policies include treating warnings as errors. This breaks all our builds and prevents us from adopting compose 1.5 and android 34.

@ahinton-league ahinton-league closed this as not planned Won't fix, can't repro, duplicate, stale Aug 23, 2023
@ahinton-league
Copy link
Author

Dup of #335

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant