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

Running on Java 16 fails #538

Closed
sormuras opened this issue Oct 24, 2020 · 16 comments
Closed

Running on Java 16 fails #538

sormuras opened this issue Oct 24, 2020 · 16 comments

Comments

@sormuras
Copy link
Contributor

Running GJF google-java-format-1.9-all-deps.jar on Java 16 (16-ea+21) fails with the follow error

java.lang.NoSuchFieldError: reader
	at com.google.googlejavaformat.java.JavacTokens$CommentSavingTokenizer.processComment(JavacTokens.java:131)
	at jdk.compiler/com.sun.tools.javac.parser.JavaTokenizer.readToken(JavaTokenizer.java:949)
	at jdk.compiler/com.sun.tools.javac.parser.Scanner.nextToken(Scanner.java:115)
	at com.google.googlejavaformat.java.JavacTokens.getTokens(JavacTokens.java:88)
	at com.google.googlejavaformat.java.JavaInput.buildToks(JavaInput.java:364)
	at com.google.googlejavaformat.java.JavaInput.buildToks(JavaInput.java:334)
	at com.google.googlejavaformat.java.JavaInput.<init>(JavaInput.java:276)
	at com.google.googlejavaformat.java.Formatter.getFormatReplacements(Formatter.java:280)
	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)
@sormuras
Copy link
Contributor Author

sormuras commented Oct 24, 2020

Due to

openjdk/jdk@4f9a1ff#diff-9dd71a3938fb726eb0eb9b7b30d8727167dad2402854b38464446c7a63ca1638L90-L94

the JavaTokenizer no longer has a protected UnicodeReader reader field but extends class UnicodeReader in the same package. The driving issue was https://bugs.openjdk.java.net/browse/JDK-8254073 Tokenizer improvements

@sormuras
Copy link
Contributor Author

With #544 being merged, it'd be a good idea to add Java ea job to the test matrix (allowing it to fail) that test-drives the current early-access build of OpenJDK.

@sormuras
Copy link
Contributor Author

Preparing a PR here: https://github.com/sormuras/google-java-format/runs/1455621338 -- the JDK Early-Access job fails as expected with the error message shown in the issue description.

The overall workflow is marked as successful.
image

Although the JDK Early-Access job failed.
image

copybara-service bot pushed a commit that referenced this issue Nov 30, 2020
Addresses #538 (comment)

Fixes #548

COPYBARA_INTEGRATE_REVIEW=#548 from sormuras:jdk-ea 0ee3f7c
PiperOrigin-RevId: 344818484
robfig pushed a commit to yext/yext-java-format that referenced this issue Dec 17, 2020
* Update outdated Javadoc links

Fixes google#409

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=286092096

* Fix a crash on c-style arrays in parameters

Fixes google#374

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=286467734

* Add SBT plugin to readme

Fixes google#391

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=286493206

* annotation/parameterless annotation

Parameterless annotations aren't necessarily marker annotations.
All we can tell about a use of an annotation is that it's parameterless,
and that's how 4.8.5 is specified.

Related: google#360

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=286650854

* Tell maven-javadoc-plugin to target JDK 8

This unbreaks `mvn install` on AdoptOpenJDK 11.
Presumably it unbreaks on all JDKs >= 11.

Fixes google#429

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=288016119

* Remove trailing tabs from comments to make behavior idempotent.

Fixes google#422, fixes google#423

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=288364171

* Migrate from JSR-305 to the Checker Framework annotations

this is tangentially related to Java 11 preparedness.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=300822964

* Add Java 11 regression tests

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=301273002

* Use the built-in JDK 11 javac

instead of relying on the shaded/vendored version.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=301645476

* Increase minimum required JDK version to 11

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=301832060

* Use the default / latest supported language level

Previously the shaded javac was defaulting to Java 8, which we needed to
override to support Java 9. Now that we're using stock JDK 11 this is
unnecessary.

Also explicitly support `var`, instead of relying on it getting parsed as
an actual type name.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=302105420

* Preserve tabular arguments for mixed sign numeric lists.

Treats unary minus literals (eg -4.0) as their underlying type when checking if all elements in a tabular list are of the same Tree.Kind.

Fixes google#400, google#406

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=303137504

* Add initial support for Java 14 language features

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=303367644

* Make re-parsing of var more robust

to support uses of `var` as an identifier, with and without a type,
e.g. in `var -> {  ... }` and `int var x = 42`;
and uses of `var

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=307693554

* Update the open-source google-java-format plugin for 2020.1.

I couldn't find any good way to make this backwards compatible. Oh well.

FYI, It looks like in 2020.1, we can probably actually use the
ExternalFormatProcessor extension point instead of doing all this hacky
nonsense... they added a #format(PsiFile, TextRange) method you can override.
But I'll leave that for later because 2020.1 is out now and people are mad.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=308647308

* Fix formatting of records without an explicit constructor

Fixes google#460

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=308658958

* Support `var` in enhanced for loops

Fixes google#463

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=308891540

* Minor Javadoc improvement.

PiperOrigin-RevId: 309329483

* Fix javadoc syntax

Fix javadoc syntax by wrap `<` into an inline code block.

```
[WARNING] ...\google-java-format\core\src\main\java\com\google\googlejavaformat\java\JavaInputAstVisitor.java:2577: warning - invalid usage of tag <
```

Fixes google#454

COPYBARA_INTEGRATE_REVIEW=google#454 from sormuras:patch-1 f5583c7
PiperOrigin-RevId: 309364827

* Pre-release javadoc fixes

PiperOrigin-RevId: 309456095

* Increment versions for 1.8 release

PiperOrigin-RevId: 309467646

* Fix a crash in expression switches

`throws` statements are allows to occur in non-block expression switch cases,
which was causing the trailing `;` to be printed twice.

Fixes google#477

PiperOrigin-RevId: 310974906

* Split up the string "M" + "OE:(begin|end)_intracomment_stripping," as the full string will trigger stripping under Copybara.

Also, avoid reference to an internal link shortener, as we are making references to it an error.

Looking to the future:

When we migrate to use proper Copybara stripping directives, we could consider removing support for the old directives. Then the problem would mostly go away. However, we might end up having the same problem with Copybara directives when google-java-format's strings and method names start mentioning *them*.

PiperOrigin-RevId: 311344956

* Addition of a third party: Github Actions

- Add the possibility of formatting your code from Github directly (taking all the events of Github Actions)
- Addition of the word "old" for the eclipse plugin, since it is 1.6 release

Fixes google#487

COPYBARA_INTEGRATE_REVIEW=google#487 from av1m:master 351b737
PiperOrigin-RevId: 313312689

* Java 14 integration tests

PiperOrigin-RevId: 314566781

* Add support for yield statement

Implement visitYield.

Fixes google#489

from ntkoopman:yield b46d1f0

COPYBARA_INTEGRATE_REVIEW=google#489
PiperOrigin-RevId: 314633394

* Support --skip-removing-unused-imports in google-java-format-diff.py

Fixes google#495

COPYBARA_INTEGRATE_REVIEW=google#495 from taesu82:patch-1 91e32d4
PiperOrigin-RevId: 315560436

* Update the IDEA plugin to use google-java-format 1.8.

PiperOrigin-RevId: 318495968

* Add missing license headers.

PiperOrigin-RevId: 320733285

* Disable Appveyor builds on branches.

Our account for Appveyor allows only 1 concurrent build.  Our current Appveyor config builds every commit to a PR twice -- once as the PR and once as the branch.  This CL updates our Appveyor config to disable builds on branches, so we get only one build per PR commit.

PiperOrigin-RevId: 320734870

* Fix the google-java-format IDEA plugin for 2020.2 IDEs.

PiperOrigin-RevId: 320945302

* Update links to Spotless' new documentation layout

Also included the Spotless maven plugin (2+ years old, but not well marketed)

Fixes google#509

COPYBARA_INTEGRATE_REVIEW=google#509 from nedtwigg:patch-2 546c758
PiperOrigin-RevId: 322832707

* Bump versions to 1.9

PiperOrigin-RevId: 328160170

* Increment versions after 1.10 release

PiperOrigin-RevId: 328214914

* Bump checker-qual from 2.0.0 to 3.6.1

Fixes google#519

COPYBARA_INTEGRATE_REVIEW=google#519 from mernst:checker-qual-361 ca54cb9
PiperOrigin-RevId: 331830590

* Update the IntelliJ plugin to google-java-format 1.9.

PiperOrigin-RevId: 332323928

* Upgrade junit dependency to 4.13.1

PiperOrigin-RevId: 336966883

* Tolerate extra semi-colons in import lists

even if they're own their own line (which g-j-f does if it runs with import
cleanup disabled).

PiperOrigin-RevId: 337192414

* Move import ordering tests out of the AOSP section

follow-up to google@b769e81

PiperOrigin-RevId: 337511552

* Remove typo period in flags documentation.

I *think* they are typoes? Apologies if this is intended.

PiperOrigin-RevId: 343547804

* Introduce GitHub Actions based CI workflow

This PR introduces a CI workflow using GitHub Actions and removes the Travis CI configuration file.

Find new workflow runs for this PR here: https://github.com/sormuras/google-java-format/actions

#### TODO

- [x] Email [Notifications](https://docs.github.com/en/free-pro-team@latest/github/managing-subscriptions-and-notifications-on-github/configuring-notifications) -- register `google-java-format-dev+ci@google.com` as a watcher or let each interested use register themself?
- [ ] Test publish snapshot job on `google:master` -- after storing credential [secrets](https://github.com/google/google-java-format/settings/secrets/actions).
- [ ] Remove AppVeyor [integration](https://github.com/google/google-java-format/settings/installations) and delete `appveyor.yml` configuration file.

Closes google#543

Fixes google#544

COPYBARA_INTEGRATE_REVIEW=google#544 from sormuras:github-action a689f62
PiperOrigin-RevId: 344280060

* Check build with JDK 16-ea

Addresses google#538 (comment)

Fixes google#548

COPYBARA_INTEGRATE_REVIEW=google#548 from sormuras:jdk-ea 0ee3f7c
PiperOrigin-RevId: 344818484

* Fix GitHub Actions-based snapshot deployment

Fixes google#547

PiperOrigin-RevId: 344903246

* Delete google-java-format appveyor and travis configs

PiperOrigin-RevId: 345300707

* Miscellaneous cleanups

Startblock:
   cl-status copybara contains unknown commit in live
PiperOrigin-RevId: 345718768

* Prepare google-java-format for JDK 16 ea

* Work around change to tokenization in JDK-8254073
* Access refactored expression pattern getters reflectively
* Relax a check on a diagnostic whose position changed

PiperOrigin-RevId: 347318664

Co-authored-by: Anthony Vanelverdinghe <anthonyv.be@outlook.com>
Co-authored-by: cushon <cushon@google.com>
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Co-authored-by: Carmi Grushko <carmi@fb.com>
Co-authored-by: Eckert, Alexander <alexander.eckert@gmx.de>
Co-authored-by: Andrew Reid <andrew.k.reid@gmail.com>
Co-authored-by: plumpy <plumpy@google.com>
Co-authored-by: google-java-format Team <no-reply@google.com>
Co-authored-by: Christian Stein <sormuras@gmail.com>
Co-authored-by: cpovirk <cpovirk@google.com>
Co-authored-by: Avi Mimoun <36456709+av1m@users.noreply.github.com>
Co-authored-by: Tim Koopman <n.t.koopman@nandoe.net>
Co-authored-by: taesu82.lee <66580975+taesu82@users.noreply.github.com>
Co-authored-by: google-java-format Team <java-team-github-bot@google.com>
Co-authored-by: Eddie Aftandilian <eaftan@google.com>
Co-authored-by: Ned Twigg <ned.twigg@diffplug.com>
Co-authored-by: Michael Ernst <mernst@alum.mit.edu>
@sormuras
Copy link
Contributor Author

Did the commit labeled Work around change to tokenization in JDK-8254073 fix this issue?

It seems like google-java-format-1.9-all-deps.jar now runs on Java 16 ... except for some illegal access errors:

java -jar google-java-format-1.9-all-deps.jar [...]
[...]
java.lang.IllegalAccessError:
  class com.google.googlejavaformat.java.JavaInput (in unnamed module @0x442e0405)
  cannot access class com.sun.tools.javac.parser.Tokens$TokenKind (in module jdk.compiler) 
  because module jdk.compiler does not export com.sun.tools.javac.parser to unnamed module @0x442e0405
        at com.google.googlejavaformat.java.JavaInput.buildToks(JavaInput.java:349)
        at com.google.googlejavaformat.java.JavaInput.buildToks(JavaInput.java:334)
        at com.google.googlejavaformat.java.JavaInput.<init>(JavaInput.java:276)
        at com.google.googlejavaformat.java.Formatter.getFormatReplacements(Formatter.java:280)
        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:831)

As --illegal-access=<value> is deprecated for removal, adding these exports directives to the java launcher helps:

java
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
-jar google-java-format-1.9-all-deps.jar [...]

@cushon
Copy link
Collaborator

cushon commented Feb 17, 2021

I think it works on the latest JDK 16 ea as of 0a2f864. (The CI isn't passing with 16 ea yet because I need to update Error Prone, I'll take a look at that.)

And yes, we'll also want to document the set of --add-exports needed for 16 ea, similar to google/error-prone#1157 (comment).

@sormuras
Copy link
Contributor Author

sormuras commented Feb 17, 2021

So far so good. Looking forward to the 1.10 release of gjf.

Any clue, why does the google-java-format-1.9-all-deps.jar I downloaded in October 2020, with the set of --add-exports applied, run happily on Java 16+36-2231? I expected to see the java.lang.NoSuchFieldError: reader pop up... 🤔 ...as a) the commit you mentioned dates to December 2020 and b) my local JAR file did not change.

@cushon
Copy link
Collaborator

cushon commented Feb 17, 2021

google-java-format-1.9-all-deps.jar works for me with 16-ea+34-2216 as long as I avoid the code path that was try to reference reader, i.e. by only formatting files that don't contain comments. Any chance you were testing on a trivial example with no comments?

class T {}
$ java  --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED -jar google-java-format-1.9-all-deps.jar Y.java
class T {}
/** test */
class T {}
$ java  --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED -jar google-java-format-1.9-all-deps.jar Y.java
...
T.java: error: reader
java.lang.NoSuchFieldError: reader
	at com.google.googlejavaformat.java.JavacTokens$CommentSavingTokenizer.processComment(JavacTokens.java:131)
	at jdk.compiler/com.sun.tools.javac.parser.JavaTokenizer.readToken(JavaTokenizer.java:949)

@sormuras
Copy link
Contributor Author

Any chance you were testing on a trivial example with no comments?

Yes. Two .java files, no comments. Adding a single // ... provokes the error. Thanks for double-checking.

copybara-service bot pushed a commit that referenced this issue Feb 17, 2021
and get tests passing with latest JDK 16 EA.

#538

PiperOrigin-RevId: 357865771
copybara-service bot pushed a commit that referenced this issue Feb 17, 2021
and get tests passing with latest JDK 16 EA.

#538

PiperOrigin-RevId: 357875378
@agavrilov76
Copy link

JDK 16 is out today. Looking forward to the next release of the google formatter.

@agavrilov76
Copy link

@cushon Any plans to release a new version soon? We would like to migrate our projects google-java-formatter to Java 16. Thanks!

@cushon
Copy link
Collaborator

cushon commented Mar 31, 2021

I published a release, and documented the --add-exports= flags that are needed for JDK 16: https://github.com/google/google-java-format/releases/tag/v1.10.0

@cushon cushon closed this as completed Mar 31, 2021
sormuras added a commit to sormuras/bach that referenced this issue Apr 1, 2021
@agavrilov76
Copy link

agavrilov76 commented Apr 1, 2021

@cushon Great! Looking forward to start using it.
Perhaps it makes sense to increment the version number in the read me file?

@sormuras
Copy link
Contributor Author

sormuras commented Apr 1, 2021

Can you please push the 1.10 binaries to Maven central?

They're here: https://repo.maven.apache.org/maven2/com/google/googlejavaformat/google-java-format/1.10.0/

@cushon
Copy link
Collaborator

cushon commented Apr 1, 2021

Thanks for the reminder about the README, I'm updating it.

@agavrilov76
Copy link

Thanks!
Looks like the version in the README should be changed to 1.10.0

Can you also please release a new version of IntelliJ plugin? :)

@cushon
Copy link
Collaborator

cushon commented Apr 2, 2021

I'm adding the missing .0, and there should be a release of the IntelliJ plugin soon-ish

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

3 participants