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

instanceOf pattern bug in release 1.10.0 (not in 1.9!) #594

Closed
Polly-Schulze opened this issue Apr 14, 2021 · 4 comments
Closed

instanceOf pattern bug in release 1.10.0 (not in 1.9!) #594

Polly-Schulze opened this issue Apr 14, 2021 · 4 comments
Assignees

Comments

@Polly-Schulze
Copy link

Polly-Schulze commented Apr 14, 2021

Consider the following minimal example:

public class MinimalExample {
  public void thisIsNotFormattedCorrectly(Object something){
    if(something instanceof String somethingAsString){
      return;
    }
    //doSomethingElse
  }
}

When formatting this with the 1.9 jar: java -jar google-java-format-1.9-all-deps.jar PATH/MinimalExample.java the class is formatted correctly.

When formatting it with the 1.10 jar: java -jar google-java-format-1.10.0-all-deps.jar PATH/MinimalExample.java I get the following error:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.googlejavaformat.java.JavacTokens$CommentSavingTokenizer (file:/[PATH]/git/google-java-format-1.10.0-all-deps.jar) to field com.sun.tools.javac.parser.JavaTokenizer.reader
WARNING: Please consider reporting this to the maintainers of com.google.googlejavaformat.java.JavacTokens$CommentSavingTokenizer
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[PATH]/MinimalExample.java:3:30: error: java.lang.LinkageError: com.sun.source.tree.BindingPatternTree.getName()
	at com.google.googlejavaformat.java.java14.Java14InputAstVisitor.visitBindingPattern(Java14InputAstVisitor.java:67)
	at com.google.googlejavaformat.java.java14.Java14InputAstVisitor.visitBindingPattern(Java14InputAstVisitor.java:47)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBindingPattern.accept(JCTree.java:2231)
	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
	at com.google.googlejavaformat.java.JavaInputAstVisitor.scan(JavaInputAstVisitor.java:329)
	at com.google.googlejavaformat.java.java14.Java14InputAstVisitor.visitInstanceOf(Java14InputAstVisitor.java:207)
	at com.google.googlejavaformat.java.java14.Java14InputAstVisitor.visitInstanceOf(Java14InputAstVisitor.java:47)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCInstanceOf.accept(JCTree.java:2178)
	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
	at com.google.googlejavaformat.java.JavaInputAstVisitor.scan(JavaInputAstVisitor.java:329)
	at com.google.googlejavaformat.java.JavaInputAstVisitor.visitIf(JavaInputAstVisitor.java:1081)
	at com.google.googlejavaformat.java.JavaInputAstVisitor.visitIf(JavaInputAstVisitor.java:157)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCIf.accept(JCTree.java:1513)
	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
	at com.google.googlejavaformat.java.JavaInputAstVisitor.scan(JavaInputAstVisitor.java:329)
	at com.google.googlejavaformat.java.JavaInputAstVisitor.visitStatements(JavaInputAstVisitor.java:2181)
	at com.google.googlejavaformat.java.JavaInputAstVisitor.methodBody(JavaInputAstVisitor.java:1495)
	at com.google.googlejavaformat.java.JavaInputAstVisitor.visitMethod(JavaInputAstVisitor.java:1482)
	at com.google.googlejavaformat.java.JavaInputAstVisitor.visitMethod(JavaInputAstVisitor.java:157)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:925)
	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
	at com.google.googlejavaformat.java.JavaInputAstVisitor.scan(JavaInputAstVisitor.java:329)
	at com.google.googlejavaformat.java.JavaInputAstVisitor.addBodyDeclarations(JavaInputAstVisitor.java:3531)
	at com.google.googlejavaformat.java.JavaInputAstVisitor.visitClassDeclaration(JavaInputAstVisitor.java:2004)
	at com.google.googlejavaformat.java.java14.Java14InputAstVisitor.visitClass(Java14InputAstVisitor.java:104)
	at com.google.googlejavaformat.java.java14.Java14InputAstVisitor.visitClass(Java14InputAstVisitor.java:47)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:832)
	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
	at com.google.googlejavaformat.java.JavaInputAstVisitor.scan(JavaInputAstVisitor.java:329)
	at com.google.googlejavaformat.java.JavaInputAstVisitor.visitCompilationUnit(JavaInputAstVisitor.java:374)
	at com.google.googlejavaformat.java.JavaInputAstVisitor.visitCompilationUnit(JavaInputAstVisitor.java:157)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:603)
	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
	at com.google.googlejavaformat.java.JavaInputAstVisitor.scan(JavaInputAstVisitor.java:329)
	at com.google.googlejavaformat.java.Formatter.format(Formatter.java:170)
	at com.google.googlejavaformat.java.Formatter.getFormatReplacements(Formatter.java:291)
	at com.google.googlejavaformat.java.Formatter.formatSource(Formatter.java:267)
	at com.google.googlejavaformat.java.FormatFileCallable.call(FormatFileCallable.java:45)
	at com.google.googlejavaformat.java.FormatFileCallable.call(FormatFileCallable.java:26)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
	at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.NoSuchMethodException: com.sun.source.tree.BindingPatternTree.getName()
	at java.base/java.lang.Class.getMethod(Class.java:2201)
	at com.google.googlejavaformat.java.java14.Java14InputAstVisitor.visitBindingPattern(Java14InputAstVisitor.java:63)
	... 42 more
	Suppressed: java.lang.NoSuchMethodException: com.sun.source.tree.BindingPatternTree.getVariable()
		at java.base/java.lang.Class.getMethod(Class.java:2201)
		at com.google.googlejavaformat.java.java14.Java14InputAstVisitor.visitBindingPattern(Java14InputAstVisitor.java:58)
		... 42 more
@Polly-Schulze Polly-Schulze changed the title Instance of pattern bug in release 1.10.0 Instance of pattern bug in release 1.10.0 (not in 1.9!) Apr 14, 2021
@Polly-Schulze Polly-Schulze changed the title Instance of pattern bug in release 1.10.0 (not in 1.9!) instanceOf pattern bug in release 1.10.0 (not in 1.9!) Apr 14, 2021
@cushon
Copy link
Collaborator

cushon commented Apr 14, 2021

What version of java are you using, what is the output of java -fullversion?

@Polly-Schulze
Copy link
Author

Polly-Schulze commented Apr 15, 2021

Sorry, this is my first time writing an issue. I should`ve said so directly. It is:

java --version
openjdk 15.0.2 2021-01-19
OpenJDK Runtime Environment AdoptOpenJDK (build 15.0.2+7)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 15.0.2+7, mixed mode, sharing)

My main goal is to update to Java 16. Hence I started by updating the google java formatter and gradle. Then this occurred.

@cushon
Copy link
Collaborator

cushon commented Apr 15, 2021

Thanks! I'm working on a fix.

@cushon cushon self-assigned this Apr 15, 2021
@cushon
Copy link
Collaborator

cushon commented Apr 21, 2021

32b63aa

@cushon cushon closed this as completed Apr 21, 2021
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

2 participants