Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -478,30 +476,17 @@ public static Context resolveContext(CompilationInfo controller, Document doc, i
}
}
if (el != null && el.getKind() == ElementKind.METHOD) {
for (Element peer : el.getEnclosingElement().getEnclosedElements()) {
if (peer.getKind().name().contains("RECORD_COMPONENT")) {
try {
Class<?> recordComponent = Class.forName("javax.lang.model.element.RecordComponentElement", true, VariableTree.class.getClassLoader());
Method getAccessor = recordComponent.getDeclaredMethod("getAccessor");
Method getRecordComponents = TypeElement.class.getDeclaredMethod("getRecordComponents");
for (Element component : (Iterable<Element>) getRecordComponents.invoke(peer.getEnclosingElement())) {
if (Objects.equals(el, getAccessor.invoke(component))) {
el = component;
break;
Element enclosing = el.getEnclosingElement();
if (enclosing.getKind() == ElementKind.RECORD) {
OUTER:
for (Element peer : enclosing.getEnclosedElements()) {
if (peer.getKind() == ElementKind.RECORD_COMPONENT) {
for (RecordComponentElement rc : ((TypeElement)enclosing).getRecordComponents()) {
if (Objects.equals(el, rc.getAccessor())) {
el = rc;
break OUTER;
}
}
} catch (ClassNotFoundException ex) {
Exceptions.printStackTrace(ex);
} catch (IllegalAccessException ex) {
Exceptions.printStackTrace(ex);
} catch (IllegalArgumentException ex) {
Exceptions.printStackTrace(ex);
} catch (InvocationTargetException ex) {
Exceptions.printStackTrace(ex);
} catch (NoSuchMethodException ex) {
Exceptions.printStackTrace(ex);
} catch (SecurityException ex) {
Exceptions.printStackTrace(ex);
}
}
}
Expand Down Expand Up @@ -869,7 +854,7 @@ public Void scan(Tree tree, Void p) {
if (found != null) {
return null;
}
if (tree != null && "BINDING_PATTERN".equals(tree.getKind().name())) {
if (tree != null && tree.getKind() == Kind.BINDING_PATTERN) {
if (process(new TreePath(getCurrentPath(), tree))) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import org.openide.util.Exceptions;
import org.openide.util.lookup.ServiceProvider;
import static java.nio.file.StandardCopyOption.*;
import java.util.concurrent.atomic.AtomicBoolean;

/**
*
Expand Down Expand Up @@ -1620,6 +1621,35 @@ public void run(CompilationController parameter) throws Exception {
assertTrue(wasCalled[0]);
}

public void testNoExceptionOnInvalidMethodReference() throws Exception {
this.sourceLevel = getLatestSourceVersion();
JavacParser.DISABLE_SOURCE_LEVEL_DOWNGRADE = true;
final String code = """
package test;
public class Test {
private static void method() {
javax.swing.event.ChangeListener l = Test::in|valid;
}
}
""";
AtomicBoolean called = new AtomicBoolean();
performTest(code, new UiUtilsCaller() {
@Override public boolean open(FileObject fo, int pos) {
return false;
}
@Override public boolean open(ClasspathInfo info, ElementHandle<?> el, String fileName) {
return false;
}
@Override public void beep(boolean goToSource, boolean goToJavadoc) {
fail("Should not be called.");
}
@Override public void warnCannotOpen(String displayName) {
called.set(true);
}
}, false, false);
assertTrue(called.get());
}

private static boolean hasPatterns() {
try {
SourceVersion.valueOf("RELEASE_14"); //NOI18N
Expand Down
Loading