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

NullPointerException in JSON Deserializer #47

Closed
bjrke opened this issue Nov 10, 2019 · 3 comments · Fixed by #48
Closed

NullPointerException in JSON Deserializer #47

bjrke opened this issue Nov 10, 2019 · 3 comments · Fixed by #48
Labels
bug Something isn't working

Comments

@bjrke
Copy link
Contributor

bjrke commented Nov 10, 2019

Describe the bug
Our jenkins pipeline worked well, but then I deleted a long living branch in sonarqube (not in git!) to be able to rename the default branch from master to the name of the long living branch. Then the pipeline stopped to work.

Expected behavior
The gradle plugin should run even if there is no existing analysis.

Stacktrace

Caused by: java.lang.NullPointerException
        at com.github.mc1arke.sonarqube.plugin.scanner.CommunityProjectPullRequestsLoader.lambda$createPullRequestInfoJsonDeserialiser$0(CommunityProjectPullRequestsLoader.java:76)
        at com.google.gson.internal.bind.TreeTypeAdapter.read(TreeTypeAdapter.java:69)
        at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
        at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
        at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
        at com.google.gson.Gson.fromJson(Gson.java:922)
        at com.google.gson.Gson.fromJson(Gson.java:860)
        at com.github.mc1arke.sonarqube.plugin.scanner.CommunityProjectPullRequestsLoader.load(CommunityProjectPullRequestsLoader.java:87)
        at org.sonar.scanner.scan.branch.ProjectPullRequestsProvider.provide(ProjectPullRequestsProvider.java:47)
        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 org.picocontainer.injectors.MethodInjector.invokeMethod(MethodInjector.java:129)
        at org.picocontainer.injectors.MethodInjector.access$000(MethodInjector.java:39)
        at org.picocontainer.injectors.MethodInjector$2.run(MethodInjector.java:113)
        at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
        at org.picocontainer.injectors.MethodInjector.decorateComponentInstance(MethodInjector.java:120)
        at org.picocontainer.injectors.CompositeInjector.decorateComponentInstance(CompositeInjector.java:58)
        at org.picocontainer.injectors.Reinjector.reinject(Reinjector.java:142)
        at org.picocontainer.injectors.ProviderAdapter.getComponentInstance(ProviderAdapter.java:96)
        at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
        at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
        at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:63)
        ... 150 more

Software Versions

  • SonarQube Version: 7.8
  • Plugin Version: version contained in sonar gradle plugin v2.7.1 and v2.8
@bjrke bjrke added the bug Something isn't working label Nov 10, 2019
@bjrke
Copy link
Contributor Author

bjrke commented Nov 10, 2019

obviously the key base is missing in the api response

{"key":"38","title":"as_S2-9252_EffectiveRankingRewards","branch":"as_S2-9252_EffectiveRankingRewards","status":{"qualityGateStatus":"OK","bugs":0,"vulnerabilities":0,"codeSmells":5},"isOrphan":true,"analysisDate":"2019-11-07T14:12:10+0000","target":"develop"}

@mc1arke
Copy link
Owner

mc1arke commented Nov 10, 2019

Thanks for the report. PullRequestInfo#getBase has a CheckForNull annotation, so it would be valid to pass a null as the base parameter. I've obviously missed this as a potential scenario when writing test cases.

@bjrke
Copy link
Contributor Author

bjrke commented Nov 12, 2019

I'll prepare and test a pull request

mc1arke pushed a commit that referenced this issue Nov 19, 2019
Where a Pull Request no longer has a target branch - such as happens when the branch is deleted from SonarQube after the Pull Request is analysed - the `base` field in the branch information will be `null`. To prevent a `NullPointerException` being thrown in this scenario, an explicit check is being added for this field being `null` before attempting to extract the text value from it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants