Skip to content

Commit

Permalink
Specify explicit source compliance for ToolFactory.createScanner() API
Browse files Browse the repository at this point in the history
This avoids org.eclipse.jdt.core.compiler.InvalidInputException in
MarkerUtil.initScanner() where JDT can't parse code that is perfectly
compilable because the old API used too low default source level.

Fixes #2134
  • Loading branch information
iloveeclipse committed Aug 8, 2022
1 parent 11dbde8 commit 6b8f2d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,8 @@ This is the changelog for SpotBugs. This follows [Keep a Changelog v1.0.0](http:
Currently the versioning policy of this project follows [Semantic Versioning v2.0.0](http://semver.org/spec/v2.0.0.html).

## Unreleased - 2022-??-??
### Fixed
- Fixed InvalidInputException in Eclipse while bug reporting ([#2134](https://github.com/spotbugs/spotbugs/issues/2134))

## 4.7.1 - 2022-06-26
### Fixed
Expand Down
10 changes: 9 additions & 1 deletion eclipsePlugin/src/de/tobject/findbugs/reporter/MarkerUtil.java
Expand Up @@ -437,7 +437,15 @@ private static IScanner initScanner(IType source, ISourceRange range) throws Jav
if (charContent == null) {
return null;
}
IScanner scanner = ToolFactory.createScanner(false, false, false, true);
IScanner scanner;
IJavaProject project = source.getJavaProject();
if (project != null) {
String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
scanner = ToolFactory.createScanner(false, false, true, sourceLevel, complianceLevel);
} else {
scanner = ToolFactory.createScanner(false, false, false, true);
}
scanner.setSource(charContent);
int offset = range.getOffset();
try {
Expand Down

0 comments on commit 6b8f2d0

Please sign in to comment.