You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by tm...@apache.org on 2021/01/17 06:31:28 UTC

[netbeans] branch master updated: [NETBEANS-5253] Fix NPE in PSR-4 hint

This is an automated email from the ASF dual-hosted git repository.

tmysik pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 22e96ae  [NETBEANS-5253] Fix NPE in PSR-4 hint
     new 1d1daab  Merge pull request #2683 from KacerCZ/netbeans-5253-fix-psr4-npe
22e96ae is described below

commit 22e96ae3d10355618e0189d366c77274d5437901
Author: Tomas Prochazka <ka...@razdva.cz>
AuthorDate: Sat Jan 16 18:37:35 2021 +0100

    [NETBEANS-5253] Fix NPE in PSR-4 hint
    
    https://issues.apache.org/jira/browse/NETBEANS-5253
    
    Fixes NPE in PSR-4 hint when user navigates to PHP stubs.
    
    To test use following code:
    ```php
    $now = new \DateTime();
    ```
    and then navigate to declaration of `DateTime`.
---
 .../org/netbeans/modules/php/editor/verification/PSR4Hint.java | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/verification/PSR4Hint.java b/php/php.editor/src/org/netbeans/modules/php/editor/verification/PSR4Hint.java
index 7a44166..7b16ad3 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/verification/PSR4Hint.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/verification/PSR4Hint.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.ListIterator;
+import org.netbeans.api.annotations.common.CheckForNull;
 import org.netbeans.editor.BaseDocument;
 import org.netbeans.modules.csl.api.Hint;
 import org.netbeans.modules.csl.api.OffsetRange;
@@ -92,7 +93,7 @@ public abstract class PSR4Hint extends HintRule {
                     return;
                 }
                 NamespaceName namespaceName = node.getName();
-                if (namespaceName != null) {
+                if (namespaceName != null && getFile() != null) {
                     int endOffset = namespaceName.getEndOffset();
                     File currentDir = getFile().getParentFile();
                     ListIterator<Identifier> segmentsIterator = namespaceName.getSegments().listIterator(namespaceName.getSegments().size());
@@ -179,8 +180,12 @@ public abstract class PSR4Hint extends HintRule {
 
             @NbBundle.Messages("PSR4WrongTypeNameHintText=Type declaration name doesn't correspond to current file name.")
             private void processTypeDeclaration(TypeDeclaration node) {
+                File file = getFile();
+                if (file == null) {
+                    return;
+                }
+                String filename = file.getName();
                 String currentTypeName = CodeUtils.extractTypeName(node);
-                String filename = getFile().getName();
                 if (!filename.equals(currentTypeName + PHP_FILE_EXTENSION)) {
                     Identifier name = node.getName();
                     createHint(name, Bundle.PSR4WrongTypeNameHintText());
@@ -249,6 +254,7 @@ public abstract class PSR4Hint extends HintRule {
             }
         }
 
+        @CheckForNull
         protected File getFile() {
             return file;
         }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

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