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

Companion object 'const val' properties generate false positive if they have a non-public marker #90

Closed
martinbonnin opened this issue Jun 22, 2022 · 5 comments
Labels

Comments

@martinbonnin
Copy link
Contributor

The following:

@Target(AnnotationTarget.PROPERTY)
annotation class HiddenProperty

public class Foo {
    companion object {
        @HiddenProperty
        const val bar = "barValue"
    }
}

Generates the following pseudo Java code:

public final class Foo {
   @NotNull
   public static final String bar = "barValue";
   @NotNull
   public static final Companion Companion = new Companion((DefaultConstructorMarker)null);

   public static final class Companion {
      // $FF: synthetic method
      @HiddenProperty
      public static void getBar$annotations() {
      }

      private Companion() {
      }
   }
}

Because the synthetic method carrying the annotations is not in the same class as the field, it is ignored and the field is marked as public API even though it shouldn't.

@qwwdfsad
Copy link
Collaborator

I wonder how this translates to Java interop stability. But I guess if it's annotated and the documentation is straightforward, it shouldn't surprise anyone

@martinbonnin
Copy link
Contributor Author

Indeed, the Java story, without @OptIn annotations sounds more dangerous. I guess it's all going through documentation...

@martinbonnin
Copy link
Contributor Author

Just bumped into that again.

I wonder how this translates to Java interop stability.

This is true for all non-public markers, right? Java code doesn't really "see" them so it's all based on documentation for java callers. Or maybe recommend library authors to add @JvmSynthetic to all non-public marker annotated symbols?

martinbonnin added a commit to martinbonnin/binary-compatibility-validator that referenced this issue Jun 27, 2024
martinbonnin added a commit to martinbonnin/binary-compatibility-validator that referenced this issue Jun 27, 2024
martinbonnin added a commit to martinbonnin/binary-compatibility-validator that referenced this issue Jun 27, 2024
@martinbonnin
Copy link
Contributor Author

Attempt at fixing this: #245

@martinbonnin
Copy link
Contributor Author

Closing as #245 was merged

ALikhachev added a commit to Kotlin/kotlinx-benchmark that referenced this issue Jul 23, 2024
Also, update the dump to reflect the actual state of the Gradle plugin.
Reorders entries in the dumps: Kotlin/binary-compatibility-validator#225, Kotlin/binary-compatibility-validator#196
Removes internal constants from the dump: Kotlin/binary-compatibility-validator#90
Fixes #248
qurbonzoda pushed a commit to Kotlin/kotlinx-benchmark that referenced this issue Aug 15, 2024
Also, update the dump to reflect the actual state of the Gradle plugin.
Reorders entries in the dumps: Kotlin/binary-compatibility-validator#225, Kotlin/binary-compatibility-validator#196
Removes internal constants from the dump: Kotlin/binary-compatibility-validator#90
Fixes #248
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants