diff --git a/javacutil/src/main/java/org/checkerframework/javacutil/Resolver.java b/javacutil/src/main/java/org/checkerframework/javacutil/Resolver.java index c1c87bb3f6c..122dfe64881 100644 --- a/javacutil/src/main/java/org/checkerframework/javacutil/Resolver.java +++ b/javacutil/src/main/java/org/checkerframework/javacutil/Resolver.java @@ -331,7 +331,13 @@ public Env getEnvForPath(TreePath path) { try { Env env = getEnvForPath(path); // Either a VariableElement or a SymbolNotFoundError. - Element res = wrapInvocationOnResolveInstance(FIND_VAR, env, names.fromString(name)); + Element res; + if (atLeastJava24) { + DiagnosticPosition pos = (DiagnosticPosition) path.getLeaf(); + res = wrapInvocationOnResolveInstance(FIND_VAR, pos, env, names.fromString(name)); + } else { + res = wrapInvocationOnResolveInstance(FIND_VAR, env, names.fromString(name)); + } // Every kind in the documentation of Element.getKind() is explicitly tested, possibly // in the "default:" case. switch (res.getKind()) {