mbien commented on code in PR #9210:
URL: https://github.com/apache/netbeans/pull/9210#discussion_r2835838884


##########
java/java.editor/src/org/netbeans/modules/editor/java/GoToSupport.java:
##########
@@ -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) {

Review Comment:
   btw for future reference: this check basically is the fix for this issue. 
Without it, javac would throw a NPE a few lines later (see reproducer).
   ```
   java.lang.NullPointerException: Cannot invoke 
"com.sun.tools.javac.code.Scope$WriteableScope.getSymbols(com.sun.tools.javac.code.Scope$LookupKind)"
 because the return value of 
"com.sun.tools.javac.code.Symbol$TypeSymbol.members()" is null
        at 
com.sun.tools.javac.code.Symbol$TypeSymbol.getEnclosedElements(Symbol.java:879)
        at 
com.sun.tools.javac.code.Symbol$TypeSymbol.getEnclosedElements(Symbol.java:818)
        at 
org.netbeans.modules.editor.java.GoToSupport.resolveContext(GoToSupport.java:481)
   ```
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to