From 13dde4efd453d32bb4f25781a8fa7aafc2cef850 Mon Sep 17 00:00:00 2001 From: aclement Date: Wed, 21 Jun 2006 11:33:21 +0000 Subject: [PATCH] test and fix for 147801: rogue bridge methods in a funky configuration. --- tests/bugs152/pr147801/Advisor.aj | 8 +++++ tests/bugs152/pr147801/Foo.java | 30 ++++++++++++++++++ tests/bugs152/pr147801/PreparedStatement.java | 3 ++ tests/bugs152/pr147801/aop.xml | 6 ++++ tests/bugs152/pr147801/foo.jar | Bin 0 -> 2106 bytes tests/bugs152/pr147801/readme.txt | 18 +++++++++++ .../systemtest/ajc152/Ajc152Tests.java | 1 + .../org/aspectj/systemtest/ajc152/ajc152.xml | 10 ++++++ weaver/src/org/aspectj/weaver/World.java | 23 ++++++++------ .../aspectj/weaver/bcel/BcelClassWeaver.java | 30 ++++++++++-------- 10 files changed, 106 insertions(+), 23 deletions(-) create mode 100644 tests/bugs152/pr147801/Advisor.aj create mode 100644 tests/bugs152/pr147801/Foo.java create mode 100644 tests/bugs152/pr147801/PreparedStatement.java create mode 100644 tests/bugs152/pr147801/aop.xml create mode 100644 tests/bugs152/pr147801/foo.jar create mode 100644 tests/bugs152/pr147801/readme.txt diff --git a/tests/bugs152/pr147801/Advisor.aj b/tests/bugs152/pr147801/Advisor.aj new file mode 100644 index 000000000..ac09aafc6 --- /dev/null +++ b/tests/bugs152/pr147801/Advisor.aj @@ -0,0 +1,8 @@ +public aspect Advisor { + + before(): staticinitialization(*oo) { + System.err.println("x"); + } + + declare parents: Foo implements java.io.Serializable; +} diff --git a/tests/bugs152/pr147801/Foo.java b/tests/bugs152/pr147801/Foo.java new file mode 100644 index 000000000..b9272c802 --- /dev/null +++ b/tests/bugs152/pr147801/Foo.java @@ -0,0 +1,30 @@ +import java.lang.reflect.Method; + +public class Foo implements PreparedStatement { + + public static void main(String []argv) throws Exception { + new Foo().getParameterMetaData(); + Method[] m = Foo.class.getMethods(); + int count = 1; + for (int i = 0; i < m.length; i++) { + Method method = m[i]; + if (method.toString().indexOf("Foo.getParameterMetaData")!=-1) + System.err.println((count++)+") "+method); + } + } + public Sub getParameterMetaData() throws MyException { + return null; + } +} + +class Sub {} + +interface PreparedStatement { +// public ParameterMetaData getParameterMetaData() throws MyException; +} + +class MyException extends Exception {} + +interface ParameterMetaData {} + +interface SubParameterMetaData extends ParameterMetaData {} diff --git a/tests/bugs152/pr147801/PreparedStatement.java b/tests/bugs152/pr147801/PreparedStatement.java new file mode 100644 index 000000000..7e6ba2547 --- /dev/null +++ b/tests/bugs152/pr147801/PreparedStatement.java @@ -0,0 +1,3 @@ +interface PreparedStatement { + public ParameterMetaData getParameterMetaData() throws MyException; +} diff --git a/tests/bugs152/pr147801/aop.xml b/tests/bugs152/pr147801/aop.xml new file mode 100644 index 000000000..5e193b9f6 --- /dev/null +++ b/tests/bugs152/pr147801/aop.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/tests/bugs152/pr147801/foo.jar b/tests/bugs152/pr147801/foo.jar new file mode 100644 index 0000000000000000000000000000000000000000..45155705d339d6329b70dbf9f4c88a69d7b26bc4 GIT binary patch literal 2106 zcmWIWW@Zs#-~hsRNmor6kN_tG3xivJzFu-pVsY`mQw$8f!KZ_S9Yt(yB`=*c_{71_ z*x97yMw4gx=-k-+U3g8=+R3y?0kOb-M^2YZ!0zw?lBN>wm)9VEcGjNM`8klIWJF=2GeN=ro(|f55$hI zV02F8>2aM9@^c&4V=W%Z83$zhcFTO1I261s`L{8TqV~pP3(oJZJb7WxHrbz>g3frp zpL#+x!&RT_cH)aI_m*rwYCTbhBVBvuSKHe+y)+kX+_72Fd*55D)V|+5Z=)}r=kOO< zs=rtCWjE_XZniwtOEzdcJUF%WzJ~a8~8vUBcDST_UUQIauPEsno%s=F;>6seGDW{*znlkyp z_PlvrJEmG#2KeWRt%%+9%hoka|Cbx{=ew&^rObT4-dQ(i(?{`>x$64mVdj!nYpkSq z*38-xt+slL=%vpc0Y`7=8967+*9a0>=^Zh}>yo15-fN#KCEY)(-O1S7_P=|5-eLQX zxus7gKAg0Q>l|y_^$Y&unrw?Mt8xb}JM6x3@+yl|x1EU<@^85JUMO57@o%$)lSu3f zwM|X?mhWo(^ow!J_1_$<7p~u4z?$Ll`trh=KTbS!_vt^PuJ$$0*1_T!v&$BKi631r z7W+9fZ4I-_vvylk%KefI;r**RXce5h$)VqmCdVPFWr znREq#$=J8jwIVsSpd>Rt50Zqfzvf@JV`F1;W{cBfOJmb3W6LXJlXGJ;n|)@_86j&o zwlvdaOl9P69?W#zl@qVCn{jl%=yPpDDX_Wc;54j_x1K}BMk!s#2Y)UtdJ?kz%p9Pn__qJ4*}LY*CKorhgAGR( z9l3L5(iNrqS0=ekKO(eX27`x}y}F@(?0tJpZPT4Cy^W0%8#@`9BqV1vst7Z41D(Xq z(Kz|S+&G{EQc;}v9B(mwelg`MmAw1Pq?B71Hu=w3mgKi) zr--tZ(BWt^pBcK-+Wqz@{@CrV)O+&Pt5pIKeXnQxrOX#~nlXQi$(pA^(q=(ksbQA) z-`-jhEO0DWR4iuc!;f>klNKvf{d;cP@L+-H&K9|t)3x4ftG`Y8E6Y;{@?gvi)md|Z zp1XwNLCms|fg!jw2|d)Qny|R8NXN`NazcSY2$G(@`=9di)k_RWNMO3f%GBe)6T-FR zW`j=4vB%cpYlK$DWgBxVm|!vZF7jCJ4A{y7WinJsudBn6ZOdWc}U z@&hKSGB#l9;=`S^CO){d1S55AVDJb-PF)in1)L?NnVFTDg$0a_8yJ+CxhJF~C9s0s zEWo>^FbC+OMzEV1nM4>6RTOdw0IH%;0ZN4x;Ek#kIe&qQ2n5&-EK)EE40P?tX&;or z5nu*0&Mb*+2q>E%r!Q1PtU*N@_Dq9p2q-Bc$0;Ym89oJ{2jTz# literal 0 HcmV?d00001 diff --git a/tests/bugs152/pr147801/readme.txt b/tests/bugs152/pr147801/readme.txt new file mode 100644 index 000000000..28e5daad5 --- /dev/null +++ b/tests/bugs152/pr147801/readme.txt @@ -0,0 +1,18 @@ +to rebuild foo.jar: + + +Build Foo.java - it includes a definition of PreparedStatement with no method specified + +mkdir out +javac -d out Foo.java + +Build a new PreparedStatement that includes the method + +javac -d out PreparedStatement.java + +Build the jar + +cd out +jar -cvMf ../foo.jar * + +You now have a jar where the Foo.class contains an invalid override... diff --git a/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java b/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java index f0be4c6ee..22c02cd03 100644 --- a/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java @@ -32,6 +32,7 @@ public class Ajc152Tests extends org.aspectj.testing.XMLBasedAjcTestCase { // public void testBrokenIfArgsCflowAtAj_pr145018() { runTest("ataj crashing with cflow, if and args");} // public void testItdCallingGenericMethod_pr145391() { runTest("itd calling generic method");} // public void testItdCallingGenericMethod_pr145391_2() { runTest("itd calling generic method - 2");} + public void testDuplicateBridgeMethods_pr147801_1() { runTest("duplicate bridge methods");} public void testPackageIgnoredForException_pr147701_1() { runTest("package for exception ignored");} public void testPackageIgnoredForException_pr147701_2() { runTest("package for exception ignored - 2");} public void testPackageIgnoredForException_pr147701_3() { runTest("package for exception ignored - 3");} diff --git a/tests/src/org/aspectj/systemtest/ajc152/ajc152.xml b/tests/src/org/aspectj/systemtest/ajc152/ajc152.xml index d6a132ee5..370d24ad9 100644 --- a/tests/src/org/aspectj/systemtest/ajc152/ajc152.xml +++ b/tests/src/org/aspectj/systemtest/ajc152/ajc152.xml @@ -720,4 +720,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/weaver/src/org/aspectj/weaver/World.java b/weaver/src/org/aspectj/weaver/World.java index 108fff263..5a84cdc6a 100644 --- a/weaver/src/org/aspectj/weaver/World.java +++ b/weaver/src/org/aspectj/weaver/World.java @@ -112,6 +112,7 @@ public abstract class World implements Dump.INode { private boolean fastDelegateSupportEnabled = isASMAround; private boolean runMinimalMemory = false; public boolean forDEBUG_structuralChangesCode = false; + public boolean forDEBUG_bridgingCode = false; // Records whether ASM is around ... so we might use it for delegates @@ -756,6 +757,7 @@ public abstract class World implements Dump.INode { public final static String xsetACTIVATE_LIGHTWEIGHT_DELEGATES = "activateLightweightDelegates"; // default true public final static String xsetRUN_MINIMAL_MEMORY ="runMinimalMemory"; // default true public final static String xsetDEBUG_STRUCTURAL_CHANGES_CODE = "debugStructuralChangesCode"; // default false + public final static String xsetDEBUG_BRIDGING = "debugBridging"; // default false public boolean isInJava5Mode() { return behaveInJava5Way; @@ -1136,16 +1138,19 @@ public abstract class World implements Dump.INode { } String s = p.getProperty(xsetRUN_MINIMAL_MEMORY,"false"); - runMinimalMemory = s.equalsIgnoreCase("true"); -// if (runMinimalMemory) -// getMessageHandler().handleMessage(MessageUtil.info("[runMinimalMemory=true] Optimizing bcel processing (and cost of performance) to use less memory")); + runMinimalMemory = s.equalsIgnoreCase("true"); +// if (runMinimalMemory) +// getMessageHandler().handleMessage(MessageUtil.info("[runMinimalMemory=true] Optimizing bcel processing (and cost of performance) to use less memory")); + + + s = p.getProperty(xsetDEBUG_STRUCTURAL_CHANGES_CODE,"false"); + forDEBUG_structuralChangesCode = s.equalsIgnoreCase("true"); + + s = p.getProperty(xsetDEBUG_BRIDGING,"false"); + forDEBUG_bridgingCode = s.equalsIgnoreCase("true"); - - s = p.getProperty(xsetDEBUG_STRUCTURAL_CHANGES_CODE,"false"); - forDEBUG_structuralChangesCode = s.equalsIgnoreCase("true"); - - } - checkedAdvancedConfiguration=true; + } + checkedAdvancedConfiguration=true; } } diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java index cdf6ec8ab..9425ce0b4 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java @@ -409,7 +409,7 @@ class BcelClassWeaver implements IClassWeaver { Type paramType = paramTypes[i]; body.append(InstructionFactory.createLoad(paramType, pos)); if (!newParamTypes[i].equals(paramTypes[i])) { - if (debug) System.err.println("Cast "+newParamTypes[i]+" from "+paramTypes[i]); + if (world.forDEBUG_bridgingCode) System.err.println("Bridging: Cast "+newParamTypes[i]+" from "+paramTypes[i]); body.append(fact.createCast(paramTypes[i],newParamTypes[i])); } pos+=paramType.getSize(); @@ -552,10 +552,6 @@ class BcelClassWeaver implements IClassWeaver { // **************************** start of bridge method creation code ***************** - // debug flag for bridge method creation - public static boolean debug=false; - - // FIXME asc tidy this lot up !! // FIXME asc refactor into ResolvedType or even ResolvedMember? @@ -571,7 +567,7 @@ class BcelClassWeaver implements IClassWeaver { if (methodThatMightBeGettingOverridden.getParameterTypes().length!=methodParamsArray.length) return null; // check same number of parameters if (!isVisibilityOverride(mmods,methodThatMightBeGettingOverridden,inSamePackage)) return null; - if (debug) System.err.println(" Seriously considering this might be getting overridden "+methodThatMightBeGettingOverridden); + if (typeToCheck.getWorld().forDEBUG_bridgingCode) System.err.println(" Bridging:seriously considering this might be getting overridden '"+methodThatMightBeGettingOverridden+"'"); // Look at erasures of parameters (List erased is List) boolean sameParams = true; @@ -590,7 +586,12 @@ class BcelClassWeaver implements IClassWeaver { if (typeToCheck.isParameterizedType()) { return methodThatMightBeGettingOverridden.getBackingGenericMember(); } else if (!methodThatMightBeGettingOverridden.getReturnType().getErasureSignature().equals(mrettype)) { - return methodThatMightBeGettingOverridden; // covariance + // addressing the wierd situation from bug 147801 + // just check whether these things are in the right relationship for covariance... + ResolvedType superReturn = typeToCheck.getWorld().resolve(UnresolvedType.forSignature(methodThatMightBeGettingOverridden.getReturnType().getErasureSignature())); + ResolvedType subReturn = typeToCheck.getWorld().resolve(UnresolvedType.forSignature(mrettype)); + if (superReturn.isAssignableFrom(subReturn)) + return methodThatMightBeGettingOverridden; } } return null; @@ -624,7 +625,7 @@ class BcelClassWeaver implements IClassWeaver { if (typeToCheck==null) return null; if (typeToCheck instanceof MissingResolvedTypeWithKnownSignature) return null; // we just can't tell ! - if (debug) System.err.println(" Checking for override of "+mname+" in "+typeToCheck); + if (typeToCheck.getWorld().forDEBUG_bridgingCode) System.err.println(" Bridging:checking for override of "+mname+" in "+typeToCheck); String packageName = typeToCheck.getPackageName(); if (packageName==null) packageName=""; @@ -643,7 +644,7 @@ class BcelClassWeaver implements IClassWeaver { if (o instanceof BcelTypeMunger) { BcelTypeMunger element = (BcelTypeMunger)o; if (element.getMunger() instanceof NewMethodTypeMunger) { - if (debug) System.err.println("Possible ITD candidate "+element); + if (typeToCheck.getWorld().forDEBUG_bridgingCode) System.err.println("Possible ITD candidate "+element); ResolvedMember aMethod = element.getSignature(); ResolvedMember isOverriding = isOverriding(typeToCheck,aMethod,mname,mrettype,mmods,inSamePackage,methodParamsArray); if (isOverriding!=null) return isOverriding; @@ -675,6 +676,7 @@ class BcelClassWeaver implements IClassWeaver { * See pr108101 */ public static boolean calculateAnyRequiredBridgeMethods(BcelWorld world,LazyClassGen clazz) { + world.ensureAdvancedConfigurationProcessed(); if (!world.isInJava5Mode()) return false; // just double check... the caller should have already verified this if (clazz.isInterface()) return false; // dont bother if we're an interface boolean didSomething=false; // set if we build any bridge methods @@ -704,18 +706,18 @@ class BcelClassWeaver implements IClassWeaver { if (bridgeToCandidate.isStatic()) continue; // ignore static methods if (name.endsWith("init>")) continue; // Skip constructors and static initializers - if (debug) System.err.println("Determining if we have to bridge to "+clazz.getName()+"."+name+""+bridgeToCandidate.getSignature()); + if (world.forDEBUG_bridgingCode) System.err.println("Bridging: Determining if we have to bridge to "+clazz.getName()+"."+name+""+bridgeToCandidate.getSignature()); // Let's take a look at the superclass ResolvedType theSuperclass= clazz.getSuperClass(); - if (debug) System.err.println("Checking supertype "+theSuperclass); + if (world.forDEBUG_bridgingCode) System.err.println("Bridging: Checking supertype "+theSuperclass); String pkgName = clazz.getPackageName(); UnresolvedType[] bm = BcelWorld.fromBcel(bridgeToCandidate.getArgumentTypes()); ResolvedMember overriddenMethod = checkForOverride(theSuperclass,name,psig,rsig,bridgeToCandidate.getAccessFlags(),pkgName,bm); if (overriddenMethod!=null) { boolean alreadyHaveABridgeMethod = methodsSet.contains(overriddenMethod.getName()+overriddenMethod.getSignature()); if (!alreadyHaveABridgeMethod) { - if (debug) System.err.println("Bridging to "+overriddenMethod); + if (world.forDEBUG_bridgingCode) System.err.println("Bridging:bridging to '"+overriddenMethod+"'"); createBridgeMethod(world, bridgeToCandidate, clazz, overriddenMethod); didSomething = true; continue; // look at the next method @@ -725,7 +727,7 @@ class BcelClassWeaver implements IClassWeaver { // Check superinterfaces String[] interfaces = clazz.getInterfaceNames(); for (int j = 0; j < interfaces.length; j++) { - if (debug) System.err.println("Checking superinterface "+interfaces[j]); + if (world.forDEBUG_bridgingCode) System.err.println("Bridging:checking superinterface "+interfaces[j]); ResolvedType interfaceType = world.resolve(interfaces[j]); overriddenMethod = checkForOverride(interfaceType,name,psig,rsig,bridgeToCandidate.getAccessFlags(),clazz.getPackageName(),bm); if (overriddenMethod!=null) { @@ -733,7 +735,7 @@ class BcelClassWeaver implements IClassWeaver { if (!alreadyHaveABridgeMethod) { createBridgeMethod(world, bridgeToCandidate, clazz, overriddenMethod); didSomething=true; - if (debug) System.err.println("Bridging to "+overriddenMethod); + if (world.forDEBUG_bridgingCode) System.err.println("Bridging:bridging to "+overriddenMethod); continue; // look at the next method } } -- 2.39.5