From ed4ebd81bf63de88f5fae4540a94d9733a940d11 Mon Sep 17 00:00:00 2001 From: aclement Date: Tue, 6 Mar 2007 10:03:31 +0000 Subject: [PATCH] 175039: fix and test, plus NPE guard --- .../src/org/aspectj/weaver/ReferenceType.java | 1 + .../src/org/aspectj/weaver/TypeFactory.java | 2 +- .../org/aspectj/weaver/TypeXTestCase.java | 23 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/weaver/src/org/aspectj/weaver/ReferenceType.java b/weaver/src/org/aspectj/weaver/ReferenceType.java index 31313cad8..d23ea9bed 100644 --- a/weaver/src/org/aspectj/weaver/ReferenceType.java +++ b/weaver/src/org/aspectj/weaver/ReferenceType.java @@ -278,6 +278,7 @@ public class ReferenceType extends ResolvedType { // true iff the statement "this = other" would compile. public final boolean isAssignableFrom(ResolvedType other,boolean allowMissing) { + if (other==null) return false; // not sure this should ever happen if (other.isPrimitiveType()) { if (!world.isInJava5Mode()) return false; if (ResolvedType.validBoxing.contains(this.getSignature()+other.getSignature())) return true; diff --git a/weaver/src/org/aspectj/weaver/TypeFactory.java b/weaver/src/org/aspectj/weaver/TypeFactory.java index 3168f9ca3..0191ea3ac 100644 --- a/weaver/src/org/aspectj/weaver/TypeFactory.java +++ b/weaver/src/org/aspectj/weaver/TypeFactory.java @@ -123,7 +123,7 @@ public class TypeFactory { // the type parameters of interest are only those that apply to the 'last type' in the signature // if the signature is 'PMyInterface$MyOtherType;' then there are none... String lastType = null; - int nestedTypePosition = signature.indexOf("$"); + int nestedTypePosition = signature.indexOf("$", endOfParams); // don't look for $ INSIDE the parameters if (nestedTypePosition!=-1) lastType = signature.substring(nestedTypePosition+1); else lastType = new String(signature); startOfParams = lastType.indexOf("<"); diff --git a/weaver/testsrc/org/aspectj/weaver/TypeXTestCase.java b/weaver/testsrc/org/aspectj/weaver/TypeXTestCase.java index 5505c092a..231df0c75 100644 --- a/weaver/testsrc/org/aspectj/weaver/TypeXTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/TypeXTestCase.java @@ -122,6 +122,29 @@ public class TypeXTestCase extends TestCase { } } + public void testTypeFactoryForParameterizedTypes() { + if (LangUtil.is15VMOrGreater()) { // no funny types pre 1.5 + UnresolvedType enumOfSimpleType = + TypeFactory.createTypeFromSignature("Pjava/lang/Enum;"); + assertEquals(1, enumOfSimpleType.getTypeParameters().length); + + UnresolvedType enumOfNestedType = + TypeFactory.createTypeFromSignature("Pjava/lang/Enum;"); + assertEquals(1, enumOfNestedType.getTypeParameters().length); + + // is this signature right? + UnresolvedType nestedTypeOfParameterized = + TypeFactory.createTypeFromSignature("PMyInterface$MyOtherType;"); + assertEquals(0, nestedTypeOfParameterized.getTypeParameters().length); + + // how about this one? is this valid? + UnresolvedType doublyNestedTypeSignatures = + TypeFactory.createTypeFromSignature("PMyInterface$MyOtherType;"); + assertEquals(1, doublyNestedTypeSignatures.getTypeParameters().length); + + } + } + private void checkTX(UnresolvedType tx,boolean shouldBeParameterized,int numberOfTypeParameters) { assertTrue("Expected parameterization flag to be "+shouldBeParameterized,tx.isParameterizedType()==shouldBeParameterized); if (numberOfTypeParameters==0) { -- 2.39.5