From 68b4950533594b9ce48a98b45dfaf7233d465354 Mon Sep 17 00:00:00 2001 From: Junichi Yamamoto Date: Sat, 1 Jun 2024 09:43:52 +0900 Subject: [PATCH] Prevent NPE #7170 - https://github.com/apache/netbeans/issues/7170 - Add a `null` check --- .../php/editor/codegen/SemiAttribute.java | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/codegen/SemiAttribute.java b/php/php.editor/src/org/netbeans/modules/php/editor/codegen/SemiAttribute.java index cc0690eda366..2ce349486942 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/codegen/SemiAttribute.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/codegen/SemiAttribute.java @@ -531,37 +531,38 @@ private ClassElementAttribute getCurrentClassElement() { public void visit(StaticConstantAccess node) { String clsName = CodeUtils.extractUnqualifiedClassName(node); ClassElementAttribute c = getCurrentClassElement(); - switch (clsName) { - case "self": //NOI18N - if (c != null) { - clsName = c.getName(); - } - break; - case "parent": //NOI18N - if (c != null) { - c = c.getSuperClass(); + if (clsName != null) { + switch (clsName) { + case "self": //NOI18N if (c != null) { clsName = c.getName(); } - } - break; - default: - //no-op - } - Collection nn = getNamedGlobalElements(Kind.CLASS, clsName); //NOI18N - if (!nn.isEmpty()) { - for (AttributedElement ell : nn) { - ClassElementAttribute ce = (ClassElementAttribute) ell; - if (ce != null && ce.getName().equals(clsName)) { - String name = CodeUtils.extractUnqualifiedClassName(node); - AttributedElement thisEl = ce.lookup(name, Kind.CONST); - node2Element.put(node.getDispatcher(), ce); - node2Element.put(node, thisEl); - node2Element.put(node.getConstant(), thisEl); break; + case "parent": //NOI18N + if (c != null) { + c = c.getSuperClass(); + if (c != null) { + clsName = c.getName(); + } + } + break; + default: + //no-op + } + Collection nn = getNamedGlobalElements(Kind.CLASS, clsName); //NOI18N + if (!nn.isEmpty()) { + for (AttributedElement ell : nn) { + ClassElementAttribute ce = (ClassElementAttribute) ell; + if (ce != null && ce.getName().equals(clsName)) { + String name = CodeUtils.extractUnqualifiedClassName(node); + AttributedElement thisEl = ce.lookup(name, Kind.CONST); + node2Element.put(node.getDispatcher(), ce); + node2Element.put(node, thisEl); + node2Element.put(node.getConstant(), thisEl); + break; + } } } - } super.visit(node); }