-
Notifications
You must be signed in to change notification settings - Fork 21
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
Duplicated @Deprecated
annotations when extending Java interface with deprecated default method cause java.lang.annotation.AnnotationFormatError
when accessed via Java reflection (2.13.11 regression)
#12799
Comments
Good catch — thanks for the report! I wonder how widely this will be encountered in the wild. The existence of a regression puts some pressure on us to get a 2.13.12 out after too much longer, but how much pressure isn't clear to me. |
Also not sure whether to mention it in the 2.13.11 release notes, or just assume that anyone googling the problem will land here. I'm not sure how common it is to do this particular kind of Java reflection on compiled Scala classes. (Like, is there one or more commonly used tool or library that does it, for example.) |
JVM spec is a bit unclear. Deprecation is "optional", and attributes with the same name and length might "clash", but it doesn't specify either behavior or restrictions. I don't see any reason to fail on duplicate Deprecation. Maybe it means "very deprecated" under |
java.lang.annotation.AnnotationFormatError
thrown when checking @Deprecated
annotations present on Java method through Scala class (2.13.11 regression)
I found this when using such a Scala class that I compiled with 2.13.11 (which apparently inherited a java interface with this Bean instantiation failed because they apparently hit these
|
I see that classfile parser sees both the DeprecatedAttr and its runtime counterpart; they are not distinguished internally, so both are emitted as DeprecatedAttrs in the class file. And I had expected something weird with default methods, oh well. By extension, the previously ignored DeprecatedAttrs were not present as runtime-retained attributes. |
The Scaladoc says "Annotation classes defined in Scala are not stored in classfiles in a Java-compatible manner and therefore not visible in Java reflection. In order to achieve this, the annotation has to be written in Java." I vaguely remember the interminable discussions. Now I see that the ambiguity is that Scala wants its deprecation to interoperate with the platform, so that it must be an exception to this rule. The other weirdness about default methods, and I expected one, is that an implementing class in Java does not receive a forwarding method; in Scala, it works like a trait, with a forwarder, and it is the forwarder that in turn receives the deprecated attribute. I haven't checked how other annotations are handled. But Java-defined annotations are stored according to retention policy, so Scala should at least manage that for deprecation. (There are TODOs for annots on params, etc.) Also, recall that Java has "repeatable annotations" for that use case. |
java.lang.annotation.AnnotationFormatError
thrown when checking @Deprecated
annotations present on Java method through Scala class (2.13.11 regression)@Deprecated
annotations when implementing Java interface result in java.lang.annotation.AnnotationFormatError
when accessed via Java reflection (2.13.11 regression)
@Deprecated
annotations when implementing Java interface result in java.lang.annotation.AnnotationFormatError
when accessed via Java reflection (2.13.11 regression)@Deprecated
annotations when implementing deprecated Java interface result in java.lang.annotation.AnnotationFormatError
when accessed via Java reflection (2.13.11 regression)
@Deprecated
annotations when implementing deprecated Java interface result in java.lang.annotation.AnnotationFormatError
when accessed via Java reflection (2.13.11 regression)@Deprecated
annotations when implementing deprecated Java interface cause java.lang.annotation.AnnotationFormatError
when accessed via Java reflection (2.13.11 regression)
@Deprecated
annotations when implementing deprecated Java interface cause java.lang.annotation.AnnotationFormatError
when accessed via Java reflection (2.13.11 regression)@Deprecated
annotations when extending Java interface with deprecated default method cause java.lang.annotation.AnnotationFormatError
when accessed via Java reflection (2.13.11 regression)
I got this problem also |
### What changes were proposed in this pull request? This PR aims to upgrade Scala to 2.13.11 - https://www.scala-lang.org/news/2.13.11 Additionally, this pr adds a new suppression rule for warning message: `Implicit definition should have explicit type`, this is a new compile check introduced by scala/scala#10083, we must fix it when we upgrading to use Scala 3, ### Why are the changes needed? This release improves collections, adds support for JDK 20 and 21, adds support for JDK 17 `sealed`: - scala/scala#10363 - scala/scala#10184 - scala/scala#10397 - scala/scala#10348 - scala/scala#10105 There are 2 known issues in this version: - scala/bug#12800 - scala/bug#12799 For the first one, there is no compilation warning messages related to `match may not be exhaustive` in Spark compile log, and for the second one, there is no case of `method.isAnnotationPresent(Deprecated.class)` in Spark code, there is just https://github.com/apache/spark/blob/8c84d2c9349d7b607db949c2e114df781f23e438/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/JavaTypeInference.scala#L130 in Spark Code, and I checked `javax.annotation.Nonnull` no this issue. So I think These two issues will not affect Spark itself, but this doesn't mean it won't affect the code written by end users themselves The full release notes as follows: - https://github.com/scala/scala/releases/tag/v2.13.11 ### Does this PR introduce _any_ user-facing change? Yes, this is a Scala version change. ### How was this patch tested? - Existing Test - Checked Java 8/17 + Scala 2.13.11 using GA, all test passed Java 8 + Scala 2.13.11: https://github.com/LuciferYang/spark/runs/14337279564 Java 17 + Scala 2.13.11: https://github.com/LuciferYang/spark/runs/14343012195 Closes #41626 from LuciferYang/SPARK-40497. Authored-by: yangjie01 <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
### What changes were proposed in this pull request? This PR aims to upgrade Scala to 2.13.11 - https://www.scala-lang.org/news/2.13.11 Additionally, this pr adds a new suppression rule for warning message: `Implicit definition should have explicit type`, this is a new compile check introduced by scala/scala#10083, we must fix it when we upgrading to use Scala 3, ### Why are the changes needed? This release improves collections, adds support for JDK 20 and 21, adds support for JDK 17 `sealed`: - scala/scala#10363 - scala/scala#10184 - scala/scala#10397 - scala/scala#10348 - scala/scala#10105 There are 2 known issues in this version: - scala/bug#12800 - scala/bug#12799 For the first one, there is no compilation warning messages related to `match may not be exhaustive` in Spark compile log, and for the second one, there is no case of `method.isAnnotationPresent(Deprecated.class)` in Spark code, there is just https://github.com/apache/spark/blob/8c84d2c9349d7b607db949c2e114df781f23e438/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/JavaTypeInference.scala#L130 in Spark Code, and I checked `javax.annotation.Nonnull` no this issue. So I think These two issues will not affect Spark itself, but this doesn't mean it won't affect the code written by end users themselves The full release notes as follows: - https://github.com/scala/scala/releases/tag/v2.13.11 ### Does this PR introduce _any_ user-facing change? Yes, this is a Scala version change. ### How was this patch tested? - Existing Test - Checked Java 8/17 + Scala 2.13.11 using GA, all test passed Java 8 + Scala 2.13.11: https://github.com/LuciferYang/spark/runs/14337279564 Java 17 + Scala 2.13.11: https://github.com/LuciferYang/spark/runs/14343012195 Closes apache#41626 from LuciferYang/SPARK-40497. Authored-by: yangjie01 <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
### What changes were proposed in this pull request? This PR aims to re-upgrade Scala to 2.13.11, after SPARK-45144 was merged, the build issues mentioned in #41943 should no longer exist. - https://www.scala-lang.org/news/2.13.11 Additionally, this pr adds a new suppression rule for warning message: `Implicit definition should have explicit type`, this is a new compile check introduced by scala/scala#10083, we must fix it when we upgrading to use Scala 3 ### Why are the changes needed? This release improves collections, adds support for JDK 20 and 21, adds support for JDK 17 `sealed`: - scala/scala#10363 - scala/scala#10184 - scala/scala#10397 - scala/scala#10348 - scala/scala#10105 There are 2 known issues in this version: - scala/bug#12800 - scala/bug#12799 For the first one, there is no compilation warning messages related to `match may not be exhaustive` in Spark compile log, and for the second one, there is no case of `method.isAnnotationPresent(Deprecated.class)` in Spark code, there is just https://github.com/apache/spark/blob/8c84d2c9349d7b607db949c2e114df781f23e438/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/JavaTypeInference.scala#L130 in Spark Code, and I checked `javax.annotation.Nonnull` no this issue. So I think These two issues will not affect Spark itself, but this doesn't mean it won't affect the code written by end users themselves The full release notes as follows: - https://github.com/scala/scala/releases/tag/v2.13.11 ### Does this PR introduce _any_ user-facing change? Yes, this is a Scala version change. ### How was this patch tested? - Existing Test ### Was this patch authored or co-authored using generative AI tooling? No Closes #42918 from LuciferYang/SPARK-40497-2. Authored-by: yangjie01 <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
This PR aims to re-upgrade Scala to 2.13.11, after SPARK-45144 was merged, the build issues mentioned in apache#41943 should no longer exist. - https://www.scala-lang.org/news/2.13.11 Additionally, this pr adds a new suppression rule for warning message: `Implicit definition should have explicit type`, this is a new compile check introduced by scala/scala#10083, we must fix it when we upgrading to use Scala 3 This release improves collections, adds support for JDK 20 and 21, adds support for JDK 17 `sealed`: - scala/scala#10363 - scala/scala#10184 - scala/scala#10397 - scala/scala#10348 - scala/scala#10105 There are 2 known issues in this version: - scala/bug#12800 - scala/bug#12799 For the first one, there is no compilation warning messages related to `match may not be exhaustive` in Spark compile log, and for the second one, there is no case of `method.isAnnotationPresent(Deprecated.class)` in Spark code, there is just https://github.com/apache/spark/blob/8c84d2c9349d7b607db949c2e114df781f23e438/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/JavaTypeInference.scala#L130 in Spark Code, and I checked `javax.annotation.Nonnull` no this issue. So I think These two issues will not affect Spark itself, but this doesn't mean it won't affect the code written by end users themselves The full release notes as follows: - https://github.com/scala/scala/releases/tag/v2.13.11 Yes, this is a Scala version change. - Existing Test No Closes apache#42918 from LuciferYang/SPARK-40497-2. Authored-by: yangjie01 <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
Reproduction steps
Scala version: 2.13.11
Reproducer is here: run
sbt test
showcases the behavior.Changing scala version to 2.13.10 solves it.
https://github.com/DieBauer/scala-reproducer/tree/master
this is compiled in a separate stage (module)
and the scala class is
then checking that the Deprecated annotation is present on the Scala class/method fails
This fails with
java.lang.annotation.AnnotationFormatError: Duplicate annotation for class: interface java.lang.Deprecated: @java.lang.Deprecated(forRemoval=false, since="")
possibly introduced by scala/scala#10291
Problem
This issue is reproduced on Java 8, 11 and 17 (potentially higher versions as well).
On 2.13.10 it does not occur.
When a Java class has a Deprecated method that is inherited in a Scala class, then checking the method through the scala class for present annotations throws a
java.lang.annotation.AnnotationFormatError: Duplicate annotation for class: interface java.lang.Deprecated: @java.lang.Deprecated(forRemoval=false, since="")
The issue is the duplicate Deprecated annotation in the bytecode when compiled with Scala 2.13.11
Details
The java class bytecode looks like:
While the scala class bytecode looks like
The same class compiled with Scala 2.13.10 gives this bytecode:
This has only 1
The text was updated successfully, but these errors were encountered: