Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NullPointerException in AbstractCxxPublicApiVisitor.visitTemplateDeclaration #2180

Closed
Nekto89 opened this issue Jun 7, 2021 · 4 comments · Fixed by #2182
Closed
Assignees
Labels
Milestone

Comments

@Nekto89
Copy link

Nekto89 commented Jun 7, 2021

Describe the bug
SonarScanner fails to import source file because of java.lang.NullPointerException. Analysis of same file through cxx-sslr-toolkit-2.0.2.2734.jar works without problems.

To Reproduce
Sadly I can't share this code. Also I'm not sure how to minimize it if sslr-toolkit doesn't crash. I've tried copying defines and includes but it doesn't change anything.

Desktop (please complete the following information):

  • OS: Windows
  • SonarQube version: 8.9.0
  • cxx plugin version: 2.0.2
  • sonar-scanner version: tried on 4.6.2.2472 and sonar-scanner-cli-4.5.0.2216

Additional context
12:42:30.504 ERROR: Error during SonarScanner execution
org.sonar.cxx.squidbridge.api.AnalysisException: Unable to parse file: ....hxx
at org.sonar.cxx.squidbridge.AstScanner.scanInputFiles(AstScanner.java:134)
at org.sonar.plugins.cxx.CxxSquidSensor.execute(CxxSquidSensor.java:299)
at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
at org.sonar.scanner.sensor.ProjectSensorsExecutor.execute(ProjectSensorsExecutor.java:49)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:360)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:150)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at com.sun.proxy.$Proxy0.execute(Unknown Source)
at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.lang.NullPointerException
at org.sonar.cxx.visitors.AbstractCxxPublicApiVisitor.visitTemplateDeclaration(AbstractCxxPublicApiVisitor.java:655)
at org.sonar.cxx.visitors.AbstractCxxPublicApiVisitor.visitDeclarator(AbstractCxxPublicApiVisitor.java:527)
at org.sonar.cxx.visitors.AbstractCxxPublicApiVisitor.visitSingleDeclarator(AbstractCxxPublicApiVisitor.java:519)
at org.sonar.cxx.visitors.AbstractCxxPublicApiVisitor.visitDeclaratorList(AbstractCxxPublicApiVisitor.java:473)
at org.sonar.cxx.visitors.AbstractCxxPublicApiVisitor.visitNode(AbstractCxxPublicApiVisitor.java:410)
at com.sonar.sslr.impl.ast.AstWalker.visitNode(AstWalker.java:114)
at com.sonar.sslr.impl.ast.AstWalker.visit(AstWalker.java:85)
at com.sonar.sslr.impl.ast.AstWalker.visitChildren(AstWalker.java:99)
at com.sonar.sslr.impl.ast.AstWalker.visit(AstWalker.java:87)
at com.sonar.sslr.impl.ast.AstWalker.visitChildren(AstWalker.java:99)
at com.sonar.sslr.impl.ast.AstWalker.visit(AstWalker.java:87)
at com.sonar.sslr.impl.ast.AstWalker.visitChildren(AstWalker.java:99)
at com.sonar.sslr.impl.ast.AstWalker.visit(AstWalker.java:87)
at com.sonar.sslr.impl.ast.AstWalker.visitChildren(AstWalker.java:99)
at com.sonar.sslr.impl.ast.AstWalker.visit(AstWalker.java:87)
at com.sonar.sslr.impl.ast.AstWalker.visitChildren(AstWalker.java:99)
at com.sonar.sslr.impl.ast.AstWalker.visit(AstWalker.java:87)
at com.sonar.sslr.impl.ast.AstWalker.walkAndVisit(AstWalker.java:69)
at org.sonar.cxx.squidbridge.AstScanner.walkAndVisit(AstScanner.java:155)
at org.sonar.cxx.squidbridge.AstScanner.scanInputFiles(AstScanner.java:132)
... 23 more

@guwirth
Copy link
Collaborator

guwirth commented Jun 7, 2021

Hi @Nekto89,

thanks for your feedback.

The interesting part seems to be:

Caused by: java.lang.NullPointerException
at org.sonar.cxx.visitors.AbstractCxxPublicApiVisitor.visitTemplateDeclaration(AbstractCxxPublicApiVisitor.java:655)

    var declId = templateDeclaration.getFirstDescendant(CxxGrammarImpl.declaratorId);
    if (declId == null) {
      return;
    }
    var idNode = declId.getLastChild(qualifiedId);
    if (idNode != null) {
      idNode = idNode.getLastChild(IDENTIFIER);
    } else {
      idNode = declId;
    }
    String id = idNode.getTokenValue();

There seems to be a problem with a template declaration. Because the SSLR toolkit does not use the Public API visitor you don't get it there. Could you provide the template declaration creating the crash?

declaratorId
   LastChild => qualifiedId
      LastChild => IDENTIFIER => null

Regards,

@guwirth guwirth added bug and removed question labels Jun 7, 2021
@guwirth guwirth added this to the 2.0.2 milestone Jun 7, 2021
@Nekto89
Copy link
Author

Nekto89 commented Jun 7, 2021

It seems to be caused by destructor

template <typename B>
A<B>::~A() = default;

@guwirth guwirth modified the milestones: 2.0.2, 2.0.3 Jun 7, 2021
guwirth added a commit to guwirth/sonar-cxx that referenced this issue Jun 7, 2021
- NPE in case of unqualifiedid
- improved error message: create id from declaratorId token stream (instead of IDENTIFIER only)
- closd SonarOpenCommunity#2180
@guwirth guwirth mentioned this issue Jun 7, 2021
@guwirth guwirth self-assigned this Jun 7, 2021
guwirth added a commit that referenced this issue Jun 7, 2021
@guwirth
Copy link
Collaborator

guwirth commented Jun 7, 2021

Hi @Nekto89, please try with snapshot after merge of #2182 is finished https://ci.appveyor.com/project/SonarOpenCommunity/sonar-cxx/branch/master/artifacts

@Nekto89
Copy link
Author

Nekto89 commented Jun 7, 2021

@guwirth crash is gone, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants