INRIA / INRIA/spoon

NPE in spoon.support.compiler.jdt.ReferenceBuilder.tryRecoverTypeArguments(ReferenceBuilder.java:611)

Open
#3,594 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2k
Forks
392
Avg merge
11h 24m
Merged PRs (30d)
36

Description

In a code sample similar to the following:

Code sample

```java
private GrpcToReactorMethodBinding findReactorMethod(MethodDescriptor methodDescriptor) {
// ...

// Check method arguments
if (reactorMethod.getParameterCount() == 0) {
// ...
return new GrpcToReactorMethodBinding<>(methodDescriptor, reactorMethod, -1, isMono, returnTypeParameter);
}
// ...
}
```

a NPE is thrown on ReferenceBuilder.java:611 as `ParameterizedTypeBinding.typeArguments` is a null array, with `alloc.sourceStart` pointing to the start of the `new` keyword.

Excerpt of GrpcToReactorMethodBinding is as follows:

GrpcToReactorMethodBinding code

```java
class GrpcToReactorMethodBinding {

// ...

GrpcToReactorMethodBinding(MethodDescriptor methodDescriptor,
Method reactorMethod,
int callMetadataPos,
boolean isMono,
Class returnTypeParameter) {
// ...
}
// ...
}
```

Stacktrace

```
Exception in thread "main" java.lang.NullPointerException: Cannot read the array length because "" is null
at spoon.support.compiler.jdt.ReferenceBuilder.tryRecoverTypeArguments(ReferenceBuilder.java:611)
at spoon.support.compiler.jdt.ReferenceBuilder.insertGenericTypesInNoClasspathFromJDTInSpoon(ReferenceBuilder.java:575)
at spoon.support.compiler.jdt.ReferenceBuilder.getTypeReference(ReferenceBuilder.java:517)
at spoon.support.compiler.jdt.ReferenceBuilder.buildTypeReference(ReferenceBuilder.java:136)
at spoon.support.compiler.jdt.ReferenceBuilder.buildTypeReference(ReferenceBuilder.java:130)
at spoon.support.compiler.jdt.JDTTreeBuilder.createParameterizedType(JDTTreeBuilder.java:1450)
at spoon.support.compiler.jdt.JDTTreeBuilder.visit(JDTTreeBuilder.java:1438)
at org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference.traverse(ParameterizedSingleTypeReference.java:405)
at org.eclipse.jdt.internal.compiler.ast.AllocationExpression.traverse(AllocationExpression.java:713)
at org.eclipse.jdt.internal.compiler.ast.ReturnStatement.traverse(ReturnStatement.java:379)
at org.eclipse.jdt.internal.compiler.ast.Block.traverse(Block.java:148)
at org.eclipse.jdt.internal.compiler.ast.IfStatement.traverse(IfStatement.java:293)
at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.traverse(MethodDeclaration.java:365)
at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1479)
at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(CompilationUnitDeclaration.java:826)
at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(CompilationUnitDeclaration.java:787)
at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.lambda$buildModel$0(JDTBasedSpoonCompiler.java:437)
at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.forEachCompilationUnit(JDTBasedSpoonCompiler.java:466)
at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildModel(JDTBasedSpoonCompiler.java:435)
at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildUnitsAndModel(JDTBasedSpoonCompiler.java:372)
at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildSources(JDTBasedSpoonCompiler.java:337)
at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:114)
at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:97)
at spoon.Launcher.buildModel(Launcher.java:755)
at lsifjava.ProjectIndexer.index(ProjectIndexer.java:125)
at lsifjava.Main.main(Main.java:18)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.