Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-3002

NullPointerExceptions during PHPStan inspection

    XMLWordPrintableJSON

Details

    Description

      PHPStan code analysis support reports NullPointerExceptions at some occasions. When the exception occurs, the Inspect dialog window is not closed on its own.

      I've been able to reproduce it using the uploaded sample project. Run composer install, then configure NetBeans to use PHPStan from vendor/bin and the configuration from phpstan.neon file in the project root.

      The configuration file contains ignoreErrors section with a pattern to ignore known errors. The exception seems to depend on whether this pattern is there or not (to disable, comment the line with #).

      To reproduce, select the app folder and run PHPStan inspection with the scope: Current folder (app).

      With the setup above I've encountered two types of the stack traces:

      Without ignore pattern (commented line)

      Output:

      "C:\Workspace\Test\PHPStanException\vendor\bin\phpstan.bat" "analyse" "--no-ansi" "--no-progress" "--no-interaction" "--error-format=checkstyle" "--level=5" "--configuration=C:\Workspace\Test\PHPStanException\phpstan.neon" "C:\Workspace\Test\PHPStanException\app"
      <?xml version="1.0" encoding="UTF-8"?>
      <checkstyle>
      <file name="app\Something.php">
        <error line="13" column="1" severity="error" message="Binary operation &quot;+&quot; between string and 2 results in an error." />
      </file>
      <file name="app\index.php">
        <error line="9" column="1" severity="error" message="Anonymous function should return string but returns void." />
        <error line="9" column="1" severity="error" message="Result of closure (void) is used." />
      </file>
      </checkstyle>
      Done.
      

      Stack trace:

      java.lang.NullPointerException
      	at org.netbeans.modules.php.analysis.util.Mappers.map(Mappers.java:54)
      	at org.netbeans.modules.php.analysis.PHPStanAnalyzerImpl.doAnalyze(PHPStanAnalyzerImpl.java:140)
      	at org.netbeans.modules.php.analysis.PHPStanAnalyzerImpl.analyze(PHPStanAnalyzerImpl.java:92)
      	at org.netbeans.modules.analysis.RunAnalysis$1$1.doRunAnalyzer(RunAnalysis.java:186)
      	at org.netbeans.modules.analysis.RunAnalysis$1$1.run(RunAnalysis.java:142)
      	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1418)
      	at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
      	at org.openide.util.lookup.Lookups.executeWith(Lookups.java:278)
      [catch] at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2033)
      

      With ignore pattern

      Output:

      "C:\Workspace\Test\PHPStanException\vendor\bin\phpstan.bat" "analyse" "--no-ansi" "--no-progress" "--no-interaction" "--error-format=checkstyle" "--level=5" "--configuration=C:\Workspace\Test\PHPStanException\phpstan.neon" "C:\Workspace\Test\PHPStanException\app"
      <?xml version="1.0" encoding="UTF-8"?>
      <checkstyle>
      <file name="app\Something.php">
        <error line="13" column="1" severity="error" message="Binary operation &quot;+&quot; between string and 2 results in an error." />
      </file>
      <file name="app\index.php">
        <error line="9" column="1" severity="error" message="Anonymous function should return string but returns void." />
        <error line="9" column="1" severity="error" message="Result of closure (void) is used." />
      </file>
      <file>
        <error severity="error" message="Ignored error pattern #Call to an undefined method Cz\\Test\\Nothing# was not matched in reported errors." />
      </file>
      </checkstyle>
      Done.
      

      Stack trace:

      java.lang.NullPointerException
      	at org.netbeans.modules.php.analysis.parsers.PHPStanReportParser.sanitizeFileName(PHPStanReportParser.java:199)
      	at org.netbeans.modules.php.analysis.parsers.PHPStanReportParser.getCurrentFile(PHPStanReportParser.java:180)
      	at org.netbeans.modules.php.analysis.parsers.PHPStanReportParser.processFileStart(PHPStanReportParser.java:133)
      	at org.netbeans.modules.php.analysis.parsers.PHPStanReportParser.startElement(PHPStanReportParser.java:114)
      	at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:510)
      	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1397)
      	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2710)
      	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
      	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:534)
      	at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:888)
      	at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:824)
      	at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
      	at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1216)
      	at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:635)
      	at org.netbeans.modules.php.analysis.parsers.PHPStanReportParser.create(PHPStanReportParser.java:68)
      	at org.netbeans.modules.php.analysis.parsers.PHPStanReportParser.parse(PHPStanReportParser.java:77)
      	at org.netbeans.modules.php.analysis.commands.PHPStan.analyze(PHPStan.java:117)
      	at org.netbeans.modules.php.analysis.PHPStanAnalyzerImpl.doAnalyze(PHPStanAnalyzerImpl.java:133)
      	at org.netbeans.modules.php.analysis.PHPStanAnalyzerImpl.analyze(PHPStanAnalyzerImpl.java:92)
      	at org.netbeans.modules.analysis.RunAnalysis$1$1.doRunAnalyzer(RunAnalysis.java:186)
      	at org.netbeans.modules.analysis.RunAnalysis$1$1.run(RunAnalysis.java:142)
      	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1418)
      	at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
      	at org.openide.util.lookup.Lookups.executeWith(Lookups.java:278)
      [catch] at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2033)
      

      Attachments

        1. PHPStanException.zip
          2 kB
          Czukowski

        Issue Links

          Activity

            People

              junichi11 Junichi Yamamoto
              czukowski Czukowski
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 50m
                  1h 50m