Bug 99089

Summary: [generics][itds] ArrayIndexOutOfBoundsException - Generics in privileged aspects
Product: [Tools] AspectJ Reporter: William Ono <wmono>
Component: CompilerAssignee: Adrian Colyer <adrian.colyer>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: DEVELOPMENT   
Target Milestone: 1.5.0 M3   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description William Ono CLA 2005-06-08 19:49:29 EDT
This is on AspectJ 1.5.0.20050525133001 as the AJDT dev build hasn't been
updated since then.  Eclipse 3.1M7, AJDT 1.2.0.20050525133001.

The problem seems to be caused by accessing a private method returning a
parameterized type from inside a privileged aspect.  (Bug 96111 seems to be
similar but for private fields.  I can't easily see if that fix fixes this one
too but the exception is quite different.)  Sample follows.


Stack trace:

java.lang.ArrayIndexOutOfBoundsException: 0
	at
org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.substitute(ParameterizedTypeBinding.java:646)
	at
org.aspectj.org.eclipse.jdt.internal.compiler.lookup.Scope.substitute(Scope.java:85)
	at
org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.substitute(ParameterizedTypeBinding.java:667)
	at
org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.superclass(ParameterizedTypeBinding.java:731)
	at
org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.isSuperclassOf(ReferenceBinding.java:743)
	at
org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.isCompatibleWith(ReferenceBinding.java:674)
	at
org.aspectj.org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.resolve(LocalDeclaration.java:207)
	at
org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatements(AbstractMethodDeclaration.java:415)
	at
org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.resolveStatements(MethodDeclaration.java:160)
	at
org.aspectj.ajdt.internal.compiler.ast.AdviceDeclaration.resolveStatements(AdviceDeclaration.java:130)
	at
org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(AbstractMethodDeclaration.java:393)
	at
org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1026)
	at
org.aspectj.ajdt.internal.compiler.ast.AspectDeclaration.resolve(AspectDeclaration.java:110)
	at
org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1075)
	at
org.aspectj.org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:280)
	at
org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:546)
	at
org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:365)
	at
org.aspectj.ajdt.internal.core.builder.AjBuildManager.performCompilation(AjBuildManager.java:727)
	at
org.aspectj.ajdt.internal.core.builder.AjBuildManager.doBuild(AjBuildManager.java:229)
	at
org.aspectj.ajdt.internal.core.builder.AjBuildManager.incrementalBuild(AjBuildManager.java:147)
	at org.aspectj.ajde.internal.CompilerAdapter.compile(CompilerAdapter.java:116)
	at
org.aspectj.ajde.internal.AspectJBuildManager$CompilerThread.run(AspectJBuildManager.java:191)




DataClass.java:

import java.util.Vector;
public class DataClass {
	private Vector<Object> v = new Vector<Object>();
	private Vector<Object> getV() { return v; }
}


TracingAspect.java:

import java.util.Vector;
privileged aspect TracingAspect {
	before(DataClass dc): execution(* DataClass.doit()) && this(dc) {
		Vector<Object> myV = dc.getV();
	}
}


Thanks.
Comment 1 Andrew Clement CLA 2005-06-09 09:55:10 EDT
Fails on the latest compiler like this:

Unexpected error messages:
	error at Vector<Object> myV = dc.getV();
               
TracingAspect.java:5:0::0 Type mismatch: cannot convert from Vector<E> to
Vector<Object>

Comment 2 Andrew Clement CLA 2005-06-09 09:59:00 EDT
Test created in Ajc150Tests.java but commented out for now ...
Comment 3 Andrew Clement CLA 2005-06-14 05:29:18 EDT
The problem here is that AjcMemberMaker.privilegedAccessForMethod() is losing
the information about the parameterized type Vector<Object> and defaulting to
the generic type Vector<E>.  Fundamentally, creation of a TypeX from a generic
signature isn't working - it will let a signature through but ignore the
generics information, rather than storing it as part of the TypeX object.  I've
fixed the TypeX processing to actually process generic information.  So now, if
you call:

TypeX.forSignature(Ljava/util/Map<Ljava/util/List<Ljava/lang/String;>;Ljava/lang/String;>;"

you will get this kind of structure to your returned TypeX:

 TypeX:
sig=Ljava/util/Map<Ljava/util/List<Ljava/lang/String;>;Ljava/lang/String;>;
parameterized=true #params=2
  param1: TypeX:  sig=Ljava/util/List<Ljava/lang/String;>; parameterized=true
#params=1
    param1: TypeX:  sig=Ljava/lang/String; parameterized=false #params=0
  param2: TypeX:  sig=Ljava/lang/String; parameterized=false #params=0

this *may* help other generics tests to start working !
Comment 4 Andrew Clement CLA 2005-06-14 10:57:53 EDT
Fix checked in, waiting on build before closing.
Comment 5 Andrew Clement CLA 2005-06-14 12:05:01 EDT
Fix available, see aspectj download page: aspectj-DEVELOPMENT-20050614164300.jar