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

Faulty mutator with Sealed interfaces since 6.20.0 version #713

Closed
cmauri75 opened this issue Dec 4, 2023 · 5 comments
Closed

Faulty mutator with Sealed interfaces since 6.20.0 version #713

cmauri75 opened this issue Dec 4, 2023 · 5 comments

Comments

@cmauri75
Copy link

cmauri75 commented Dec 4, 2023

Since 6.20 gradle spotlessapply fails when analyzing a sealed interface, this is the dum:

....
Caused by: java.lang.IllegalArgumentException: Issue with a cleanthat mutator. Around lines: public sealed interface IUpdatePortCommand permits UpdateScheduleCommand, UpdateStateCommand {} 

Please report it to 'https:/solven-eu/cleanthat/issues' referring the faulty mutator: 'eu.solven.cleanthat.engine.java.refactorer.mutators.ModifierOrder with as testCase: 

public sealed interface IUpdatePortCommand {
}
        at eu.solven.cleanthat.engine.java.refactorer.AJavaparserAstMutator.executeOnNode(AJavaparserAstMutator.java:227)
        at eu.solven.cleanthat.engine.java.refactorer.AJavaparserAstMutator.walkOneNode(AJavaparserAstMutator.java:116)
        at eu.solven.cleanthat.engine.java.refactorer.AJavaparserAstMutator.lambda$walkAst$0(AJavaparserAstMutator.java:67)
        at com.github.javaparser.ast.Node.walk(Node.java:862)
        at com.github.javaparser.ast.Node.walk(Node.java:870)
        at eu.solven.cleanthat.engine.java.refactorer.AJavaparserAstMutator.walkAst(AJavaparserAstMutator.java:66)
        at eu.solven.cleanthat.engine.java.refactorer.AJavaparserAstMutator.walkAst(AJavaparserAstMutator.java:41)
        at eu.solven.cleanthat.engine.java.refactorer.AstRefactorerInstance.applyMutator(AstRefactorerInstance.java:88)
        ... 139 more
Caused by: java.lang.UnsupportedOperationException: Csm token CsmToken(property:{) NodeText TOKEN "permits"   <46>   (line 4,col 44)-(line 4,col 50)
        at com.github.javaparser.printer.lexicalpreservation.Difference.applyKeptDiffElement(Difference.java:737)
        at com.github.javaparser.printer.lexicalpreservation.Difference.apply(Difference.java:361)
        at com.github.javaparser.printer.lexicalpreservation.LexicalDifferenceCalculator.calculatePropertyChange(LexicalDifferenceCalculator.java:167)
        at com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter$Observer.concretePropertyChange(LexicalPreservingPrinter.java:204)
        at com.github.javaparser.ast.observer.PropagatingAstObserver.propertyChange(PropagatingAstObserver.java:62)
        at com.github.javaparser.ast.Node.lambda$notifyPropertyChange$5(Node.java:621)
        at com.github.javaparser.ast.Node.notifyPropertyChange(Node.java:621)
        at com.github.javaparser.ast.body.TypeDeclaration.setModifiers(TypeDeclaration.java:133)
        at com.github.javaparser.ast.body.TypeDeclaration.setModifiers(TypeDeclaration.java:51)
        at com.github.javaparser.ast.nodeTypes.NodeWithModifiers.setModifiers(NodeWithModifiers.java:97)
        at eu.solven.cleanthat.engine.java.refactorer.mutators.ModifierOrder.processNotRecursively(ModifierOrder.java:124)
        at eu.solven.cleanthat.engine.java.refactorer.AJavaparserAstMutator.executeOnNode(AJavaparserAstMutator.java:223)
        ... 146 more

IUpdatePortCommand.java content is:

public sealed interface IUpdatePortCommand permits UpdateScheduleCommand, UpdateStateCommand {}

Formatting works fine with 6.19.0, affected versions are: 6.20 --> 6.23.3

Using:

Gradle 8.4

Build time: 2023-10-04 20:52:13 UTC
Revision: e9251e572c9bd1d01e503a0dfdf43aedaeecdc3f

Kotlin: 1.9.10
Groovy: 3.0.17
Ant: Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM: 21.0.1 (Amazon.com Inc. 21.0.1+12-LTS)
OS: Mac OS X 14.1.2 aarch64

@blacelle
Copy link
Member

blacelle commented Dec 4, 2023

Thanks for the report. I can reproduce it with a unitTest.

@blacelle
Copy link
Member

blacelle commented Dec 4, 2023

Relates with javaparser/javaparser#3935, which workaround leads to a failure with the sealed and/or permits keywords.

@blacelle
Copy link
Member

blacelle commented Dec 4, 2023

Underlying issue in JavaParser: javaparser/javaparser#4245

@blacelle
Copy link
Member

blacelle commented Dec 6, 2023

@cmauri75 I released a 2.18 version of cleanthat, which workaround this issue. Please force 2.18 as cleanthat version in Spotless (https:/diffplug/spotless/blob/main/plugin-gradle/README.md#cleanthat).

@blacelle
Copy link
Member

Please re-open if this is not fixed with latest cleanthat release.

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

No branches or pull requests

2 participants