Skip to content

Commit 2b0e11d

Browse files
committed
Fix more "Attempt to push null on operand stack" variants
This change fixes more cases in the *Declaration classes that generate code. Both #336 and #337 are due to the same piece of code not correctly computing the resolved position because of copying it from a source method when it needs recomputing for the method being generated. In particular primitive types and/or double slot types (like long or double) cause the code to miscompute the resolved positions or set the wrong type of expected type on the stack. Fixes #336 Fixes #337
1 parent e0d2b60 commit 2b0e11d

File tree

7 files changed

+54
-8
lines changed

7 files changed

+54
-8
lines changed

org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/AdviceDeclaration.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ public int getDeclaredParameterCount() {
196196

197197
private void generateProceedMethod(ClassScope classScope, ClassFile classFile) {
198198
MethodBinding binding = proceedMethodBinding;
199-
200199
classFile.generateMethodInfoHeader(binding);
201200
int methodAttributeOffset = classFile.contentsOffset;
202201
int attributeNumber = classFile.generateMethodInfoAttributes(binding, AstUtil.getAjSyntheticAttribute());
@@ -214,16 +213,17 @@ private void generateProceedMethod(ClassScope classScope, ClassFile classFile) {
214213

215214
Argument[] arguments = this.arguments;
216215
if (arguments != null) {
216+
int rp = 0;
217217
for (Argument argument: arguments) {
218218
LocalVariableBinding lvb = argument.binding;
219219
LocalVariableBinding lvbCopy = new LocalVariableBinding(lvb.name, lvb.type, lvb.modifiers, true);
220220
lvbCopy.declaration = new LocalDeclaration(argument.name, 0, 0);
221221
codeStream.record(lvbCopy);
222222
lvbCopy.recordInitializationStartPC(0);
223-
lvbCopy.resolvedPosition = lvb.resolvedPosition;
223+
lvbCopy.resolvedPosition = rp;
224+
rp += InterTypeMethodDeclaration.getSlotSize(lvb.type.id);
224225
}
225226
}
226-
227227
codeStream.aload(closureIndex);
228228

229229
// build the Object[]
@@ -242,7 +242,6 @@ private void generateProceedMethod(ClassScope classScope, ClassFile classFile) {
242242
if (type.isBaseType()) {
243243
codeStream.invoke(Opcodes.OPC_invokestatic, AjTypeConstants.getConversionMethodToObject(classScope, type), null);
244244
}
245-
246245
codeStream.aastore();
247246
}
248247

tests/bugs1924/336/Bang.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class Bang {
2+
3+
public static void main(String[] argv) {
4+
new Bang().m("a",1,"b");
5+
}
6+
7+
public int m(String a, int i, String b) {
8+
return 42;
9+
}
10+
11+
}
12+
13+
aspect X {
14+
int around(String a, int b, String d): execution(* m(..)) && args(a,b,d) {
15+
return proceed(a,b,d);
16+
}
17+
}

tests/bugs1924/337/X.aj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public aspect X {
2+
pointcut p(long l): call(* F.m(..)) && args(l);
3+
Object around (long id): p(id) { return null; }
4+
5+
public static void main(String []argv) {
6+
new F().m(3L);
7+
}
8+
}
9+
10+
class F {
11+
public void m(long r) {}
12+
}

tests/src/test/java/org/aspectj/systemtest/AllTests19.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.aspectj.systemtest.ajc1921.AllTestsAspectJ1921;
1616
import org.aspectj.systemtest.ajc1922.AllTestsAspectJ1922;
1717
import org.aspectj.systemtest.ajc1923.AllTestsAspectJ1923;
18+
import org.aspectj.systemtest.ajc1924.AllTestsAspectJ1924;
1819
import org.aspectj.systemtest.ajc193.AllTestsAspectJ193;
1920
import org.aspectj.systemtest.ajc195.AllTestsAspectJ195;
2021
import org.aspectj.systemtest.ajc196.AllTestsAspectJ196;
@@ -47,8 +48,9 @@ public static Test suite() {
4748
suite.addTest(AllTestsAspectJ1920.suite());
4849
suite.addTest(AllTestsAspectJ1921.suite());
4950
suite.addTest(AllTestsAspectJ1922.suite());
50-
// AspectJ_JDK_Update
5151
suite.addTest(AllTestsAspectJ1923.suite());
52+
// AspectJ_JDK_Update
53+
suite.addTest(AllTestsAspectJ1924.suite());
5254
suite.addTest(AllTests18.suite());
5355
// $JUnit-END$
5456
return suite;

tests/src/test/java/org/aspectj/systemtest/ajc1924/Bugs1924Tests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ public static Test suite() {
2121

2222
public void testNothing() {
2323
}
24+
25+
public void testGh336_ProceedCodeGenProblem() {
26+
runTest("proceed code gen problem 1");
27+
}
28+
29+
public void testGh337_ProceedCodeGenProblem() {
30+
runTest("proceed code gen problem 2");
31+
}
2432

2533
@Override
2634
protected java.net.URL getSpecFile() {

tests/src/test/java/org/aspectj/systemtest/ajc1924/Java24PreviewFeaturesTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ public static Test suite() {
2525
return XMLBasedAjcTestCase.loadSuite(Java24PreviewFeaturesTests.class);
2626
}
2727

28-
public void testJep455PrimitivePatternsSwitch1() {
29-
fail();
30-
// runTest("primitive types patterns - switch");
28+
public void testNothing() {
3129
}
3230

3331
@Override

tests/src/test/resources/org/aspectj/systemtest/ajc1924/ajc1924.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,15 @@
4545
</run>
4646
</ajc-test>
4747

48+
<ajc-test dir="bugs1924/336" vm="24" title="proceed code gen problem 1">
49+
<compile files="Bang.java" options="-17"/>
50+
<run class="Bang"/>
51+
</ajc-test>
52+
53+
<ajc-test dir="bugs1924/337" vm="24" title="proceed code gen problem 2">
54+
<compile files="X.aj" options="-17"/>
55+
<run class="X"/>
56+
</ajc-test>
57+
4858

4959
</suite>

0 commit comments

Comments
 (0)