Bug 120826

Summary: Varargs causes a NullPointerException
Product: [Tools] AspectJ Reporter: Pekka Enberg <penberg>
Component: CompilerAssignee: Andrew Clement <aclement>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3    
Version: 1.5.0M5   
Target Milestone: 1.5.0RC1   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Pekka Enberg CLA 2005-12-14 03:53:43 EST
The included test program causes a NullPointerException when I have AspectJ nature set for my Eclipse Project. I am using Eclipse 3.2 M3 and AJDT downloaded from here: http://www.eclipse.org/downloads/download.php?file=/technology/ajdt/32/dev/update/ajdt_1.3.0.20051117105200_archive.zip.

import java.util.Arrays;

import junit.framework.TestCase;

/**
 * @author Pekka Enberg
 */
public class TestVarargs extends TestCase {
    public void testVarargs() throws Exception {
        Arrays.asList(String.class, Integer.class, Long.class);
    }
}

This is the error:

java.lang.NullPointerException
at org.aspectj.org.eclipse.jdt.internal.compiler.lookup.Scope.lowerUpperBound(Scope.java:2999)
at org.aspectj.org.eclipse.jdt.internal.compiler.lookup.Scope.leastContainingTypeArgument(Scope.java:2961)
at org.aspectj.org.eclipse.jdt.internal.compiler.lookup.Scope.leastContainingInvocation(Scope.java:2879)
at org.aspectj.org.eclipse.jdt.internal.compiler.lookup.Scope.lowerUpperBound(Scope.java:3019)
at org.aspectj.org.eclipse.jdt.internal.compiler.lookup.Scope.lowerUpperBound(Scope.java:2979)
at org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding.resolveSubstituteConstraints(ParameterizedGenericMethodBinding.java:245)
at org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding.inferFromArgumentTypes(ParameterizedGenericMethodBinding.java:167)
at org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding.computeCompatibleMethod(ParameterizedGenericMethodBinding.java:63)
at org.aspectj.org.eclipse.jdt.internal.compiler.lookup.Scope.computeCompatibleMethod(Scope.java:352)
at org.aspectj.org.eclipse.jdt.internal.compiler.lookup.Scope.findMethod(Scope.java:1159)
at org.aspectj.org.eclipse.jdt.internal.compiler.lookup.Scope.getMethod(Scope.java:2165)
at org.aspectj.org.eclipse.jdt.internal.compiler.ast.MessageSend.resolveMethodBinding(MessageSend.java:480)
at org.aspectj.org.eclipse.jdt.internal.compiler.ast.MessageSend.resolveType(MessageSend.java:347)
at org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression.resolve(Expression.java:829)
at org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatements(AbstractMethodDeclaration.java:422)
at org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.resolveStatements(MethodDeclaration.java:178)
at org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(AbstractMethodDeclaration.java:400)
at org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1088)
at org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1137)
at org.aspectj.org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:305)
at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:514)
at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:329)
at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performCompilation(AjBuildManager.java:809)
at org.aspectj.ajdt.internal.core.builder.AjBuildManager.doBuild(AjBuildManager.java:254)
at org.aspectj.ajdt.internal.core.builder.AjBuildManager.incrementalBuild(AjBuildManager.java:163)
at org.aspectj.ajde.internal.CompilerAdapter.compile(CompilerAdapter.java:117)
at org.aspectj.ajde.internal.AspectJBuildManager$CompilerThread.run(AspectJBuildManager.java:191)

NullPointerException thrown: null
Comment 1 Andrew Clement CLA 2005-12-14 06:06:11 EST
Looks like a bug in the underlying compiler - we took a cut of the eclipse compiler for 3.1 and I can see the code in that area appears to have changed since we took a cut.  The NPE is because we are traversing an array of length 4 with only 3 things in it - representing the 3 parameters to the method.

It is length 4 because of the way the compiler chooses to double its capacity as it processes.

you can get rid of the error by passing a 4th parameter ;)
Comment 2 Andrew Clement CLA 2005-12-14 06:48:03 EST
Right - we probably need to upgrade to the latest JDT compiler version (3.1.1) but we aren't going to do that for 1.5.0 final.  So, I've put in a fix to sort out the growing of the array, it now grows by 1 and fills each slot rather than doubling in size when it gets full and other consumers downstream then not being able to rely on its size to indicate how much of it is full.

Fix is checked in . waiting on build.

thanks for the clear bug report :)
Comment 3 Andrew Clement CLA 2005-12-14 08:36:42 EST
fix available.