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

New RuleId value class mangled, preventing use in Java #2041

Closed
magneticflux- opened this issue May 18, 2023 · 7 comments · Fixed by #2042
Closed

New RuleId value class mangled, preventing use in Java #2041

magneticflux- opened this issue May 18, 2023 · 7 comments · Fixed by #2042
Milestone

Comments

@magneticflux-
Copy link

Expected Behavior

I should be able to reference, use, and construct RuleIds from Java code.

Observed Behavior

I cannot access the third property of LintError (a RuleId). The generated bytecode shows that the name is mangled, per the docs:

  // access flags 0x11
  public final getRuleId-6XN97os()Ljava/lang/String;
  @Lorg/jetbrains/annotations/NotNull;() // invisible
   L0
    LINENUMBER 17 L0
    ALOAD 0
    GETFIELD com/pinterest/ktlint/rule/engine/api/LintError.ruleId : Ljava/lang/String;
    ARETURN
   L1
    LOCALVARIABLE this Lcom/pinterest/ktlint/rule/engine/api/LintError; L0 L1 0
    MAXSTACK = 1
    MAXLOCALS = 1

This can be fixed by explicitly specifying the name with @JvmName.

Your Environment

  • Version of ktlint used: 0.49.1
@magneticflux-
Copy link
Author

magneticflux- commented May 18, 2023

A similar issue occurs for the extension properties on RuleSetId and RuleId. createRuleSetExecutionEditorConfigProperty becomes createRuleSetExecutionEditorConfigProperty-fqiwTpU and createRuleExecutionEditorConfigProperty becomes createRuleExecutionEditorConfigProperty-U7AdEiY.

magneticflux- added a commit to magneticflux-/spotless that referenced this issue May 18, 2023
Currently, we work around name-mangling issues with special Kotlin classes. The root issue is tracked here: pinterest/ktlint#2041

Also fixes the IntelliJ .editorconfig import order property to better match Eclipse formatting
paul-dingemans added a commit that referenced this issue May 19, 2023
…s. Those classes were defined as value classes in `0.49.0` and `0.49.1`. Although the classes were marked with `@JvmInline` it seems that it is not possible to uses those classes from Java base API Consumers like Spotless. The classes have now been replaced with data classes.

Closes #2041
@paul-dingemans
Copy link
Collaborator

I didn't know about interoperability issues with value classes. After some googling around, I get the feeling that those issues are known for a long time and are not very likely to be fixed:

@paul-dingemans paul-dingemans added this to the 0.49.2 milestone May 19, 2023
paul-dingemans added a commit that referenced this issue May 19, 2023
…s. Those classes were defined as value classes in `0.49.0` and `0.49.1`. Although the classes were marked with `@JvmInline` it seems that it is not possible to uses those classes from Java base API Consumers like Spotless. The classes have now been replaced with data classes. (#2042)

Closes #2041
@paul-dingemans
Copy link
Collaborator

Can you validate with the latest snapshot build whether the problem is solved? Technically, this is a breaking change and I will have to release it as 0.50.x.

@shashachu
Copy link
Contributor

@magneticflux- can you elaborate what your use case is for accessing these values from Java?

@shashachu
Copy link
Contributor

Nevermind; heard from Paul that it's for Spotless

@magneticflux-
Copy link
Author

@paul-dingemans Yep, everything seems fine here, thanks for the quick turnaround! I tested in Spotless using this patch: diffplug/spotless#1706 (comment), which I'll use as a base for the full 0.50.0 update.

My Spotless PR already supports 0.49.0 using a reflection workaround, so we're not desperate for a 0.50.0 release.

@paul-dingemans
Copy link
Collaborator

Tnx for confirming that the problem is solved. Also, I am grateful that you mentioned explicitly that for now you have worked around it with reflection. Releasing 0.50.0 without improvements for 'normal' (e.g. non API consumers) does not feel ok.

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

Successfully merging a pull request may close this issue.

3 participants