Skip to content

Commit

Permalink
Fix NoSuchMethodError happening on JDK 21 (fixes #885) (#886)
Browse files Browse the repository at this point in the history
The JDK internal class JCImport has changed recently. In JDK 17, the method was defined as:

public JCTree getQualifiedIdentifier() { return qualid; }
and in JDK 21:

public JCFieldAccess getQualifiedIdentifier() { return qualid; }

One possibility to fix that would be to fix the getSimpleName() method to use an argument of type com.sun.source.tree.ImportTree and call the getQualifiedIdentifier() method which returns a com.sun.source.tree.Tree and has not changed.
  • Loading branch information
gnodet authored Jun 20, 2023
1 parent 8163284 commit 013e6f6
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private static RangeMap<Integer, String> buildReplacements(
return replacements;
}

private static String getSimpleName(JCImport importTree) {
private static String getSimpleName(ImportTree importTree) {
return importTree.getQualifiedIdentifier() instanceof JCIdent
? ((JCIdent) importTree.getQualifiedIdentifier()).getName().toString()
: ((JCFieldAccess) importTree.getQualifiedIdentifier())
Expand Down

0 comments on commit 013e6f6

Please sign in to comment.