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

Fix jdk17 incompatibility of ClassInitializationDeadlock #1936

Merged
merged 3 commits into from Oct 18, 2021

Conversation

fawind
Copy link
Contributor

@fawind fawind commented Oct 18, 2021

Before this PR

When compiling with JDK 17 you get the following error:

An unhandled exception was thrown by the Error Prone static analysis plugin.
     error-prone version: 2.9.0
     BugPattern: ClassInitializationDeadlock
     Stack Trace:
     java.lang.NoClassDefFoundError: com/sun/tools/javac/util/Filter
        at com.palantir.baseline.errorprone.ClassInitializationDeadlock.matchClass(ClassInitializationDeadlock.java:71)
        at com.google.errorprone.scanner.ErrorProneScanner.processMatchers(ErrorProneScanner.java:450)
        at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:548)
        at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:151)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:860)
       [...]

This is due to breaking changes to the com.sun.tools.javac.util.Filter API.

Upstream error-prone also ran into this problem (issue, PR). They fixed this by adding a "compatibility wrapper" around Filter: ErrorProneScope.java. Unfortunately, the error-prone compatibility wrapper only provides the method getSymbols(Predicate<Symbol>) but not the method getSymbols(Predicate<Symbol>, LookupKind) which is the one we need.

After this PR

Closes #1926

  • Uses compatibility workaround to fix jdk 17 incompatibility.
  • Copies ErrorProneScope, adding the missing method.
    • Will FLUP with trying to upstream this method so we can delete our copy but error-prone releases are not very frequent so this might take a while.

==COMMIT_MSG==
Fix jdk17 incompatibility of ClassInitializationDeadlock
==COMMIT_MSG==

Possible downsides?

We don't have testing infra for jdk17 yet, so the jdk17 codepath is untested (although I tested in a local project).

@changelog-app
Copy link

changelog-app bot commented Oct 18, 2021

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Fix jdk17 incompatibility of ClassInitializationDeadlock

Check the box to generate changelog(s)

  • Generate changelog entry

@policy-bot policy-bot bot requested a review from robert3005 October 18, 2021 17:17

/**
* A compatibility wrapper around {@link com.sun.tools.javac.util.Filter}.
* Adapted from {@link com.google.errorprone.util.ErrorProneScope} with additional methods.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a link to ErrorProneScope.java upstream at the commit we borrowed from and note the license (Apache 2.0)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added!

Copy link
Contributor

@carterkozak carterkozak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm pending comment 👍

@bulldozer-bot bulldozer-bot bot merged commit 41d73b0 into develop Oct 18, 2021
@bulldozer-bot bulldozer-bot bot deleted the fw/jdk17-filter branch October 18, 2021 17:29
@svc-autorelease
Copy link
Collaborator

Released 4.29.0

bulldozer-bot bot pushed a commit to palantir/witchcraft-api that referenced this pull request Oct 18, 2021
###### _excavator_ is a bot for automating changes across repositories.

Changes produced by the roomba/latest-baseline-oss check.

# Release Notes
## 4.29.0
| Type | Description | Link |
| ---- | ----------- | ---- |
| Fix | Fix jdk17 incompatibility of ClassInitializationDeadlock | palantir/gradle-baseline#1936 |



To enable or disable this check, please contact the maintainers of Excavator.
This was referenced Oct 18, 2021
copybara-service bot pushed a commit to google/error-prone that referenced this pull request Oct 19, 2021
Add a compatibility helper method for `getSymbols(Predicate<Symbol>, LookupKind)`.

**Context:**
In [gradle-baseline](https://github.com/palantir/gradle-baseline#baseline-error-prone-checks), we maintain our own set of error-prone rules and ran into similar JDK 17 compatibility problems as mentioned in #2330.

However for our custom rules, we also need a compatibility helper for `getSymbols(Predicate, LookupKind)`. For now, we work around this by copying parts of the `ErrorProneScope` class (([PR](palantir/gradle-baseline#1936))) but ideally we could reuse the existing helper and wouldn't have to maintain our own fork of this class.

Fixes #2629

COPYBARA_INTEGRATE_REVIEW=#2629 from fawind:fw/get-symbols-lookup-kind e843406
PiperOrigin-RevId: 404111704
@fawind
Copy link
Contributor Author

fawind commented Oct 19, 2021

google/error-prone#2629 got merged so with the next error-prone release we should be good to remove our fork of BaselineErrorProneScope.

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

Successfully merging this pull request may close these issues.

compileJava error on JDK 17 due to java.lang.NoClassDefFoundError: com/sun/tools/javac/util/Filter
4 participants