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

Make ThirdPartyLibrary compatible with -source 8 #627

Merged
merged 1 commit into from
May 16, 2023

Conversation

Stephan202
Copy link
Member

@Stephan202 Stephan202 commented May 14, 2023

Suggested commit message:

Make `ThirdPartyLibrary` compatible with `-source 8` (#627)

When targeting Java 8, `unnamedModule` is not properly initialized,
causing an NPE when trying to load a class from it. In that context
`noModule` should be used instead.

Fixes #626.

When targeting Java 8, `unnamedModule` is not properly initialized,
causing an NPE when trying to load a class from it. In that context
`noModule` should be used instead.

Resolves #626.
@Stephan202 Stephan202 added this to the 0.12.0 milestone May 14, 2023
@Stephan202 Stephan202 requested a review from rickie May 14, 2023 18:45
@sonarcloud
Copy link

sonarcloud bot commented May 14, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

71.4% 71.4% Coverage
0.0% 0.0% Duplication

Comment on lines +93 to +97
// XXX: Drop support for targeting Java 8 once the oldest supported JDK drops such support.
ModuleSymbol module =
Source.instance(state.context).compareTo(Source.JDK9) < 0
? symtab.noModule
: symtab.unnamedModule;
Copy link
Member Author

Choose a reason for hiding this comment

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

Unconditionally using noModule seems to work as well, but:

  1. The documentation claims it should only be used with -source 8.
  2. I suspect (but did not test) that if using noModule when targeting Java 9+, the requested classes may be loaded a second time. That's not very nice/efficient.

Copy link
Member Author

Choose a reason for hiding this comment

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

Naturally Pitest complains that one of the branches isn't covered. We can't prevent that, but it does raise the question whether we should have a build targeting JDK 8. With Jabel introduced in #603 this would in theory be possible, but (a) it'd require a number of workarounds and (b) that setup doesn't seem capable of reproducing the NPE reported in #626 (not sure why; didn't deep-dive). So all-in-all not worth the hassle.

@github-actions
Copy link

  • Surviving mutants in this change: 2
  • Killed mutants in this change: 0
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.util.ThirdPartyLibrary 2 0

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Member

@rickie rickie left a comment

Choose a reason for hiding this comment

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

IIUC your comments correctly, it is not trivial to test this change, right?

Changes LGTM.

W.r.t. suggested commit message, slightly prefer Fixes over Resolves in this case 🤔.

@Stephan202
Copy link
Member Author

IIUC your comments correctly, it is not trivial to test this change, right?

Well, it can be tested using the reproduction case of #626. When using a SNAPSHOT built off this branch the NPE goes away :)

W.r.t. suggested commit message, slightly prefer Fixes over Resolves in this case thinking.

🤷

Copy link
Member

@rickie rickie left a comment

Choose a reason for hiding this comment

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

Well, it can be tested using the reproduction case of #626. When using a SNAPSHOT built off this branch the NPE goes away :)

😅 , it's time to call it a day haha.

Verified that it works, nice fix @Stephan202 🚀 !

@cernat-catalin cernat-catalin self-requested a review May 16, 2023 06:19
@rickie rickie merged commit 03af058 into master May 16, 2023
17 checks passed
@rickie rickie deleted the sschroevers/fix-java-8-source-compat branch May 16, 2023 07:53
@rickie rickie modified the milestones: 0.12.0, 0.11.1 May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

3 participants