Project: AspectJ
Bug 29665 Inconsistant stack height
Reported: 2003-01-16 15:18:00 | Status: resolved fixed

Using AspectJ1.1b4 running the following program crashes it with this message: "Inconsistent stack height 0 != 2". While reducing my original program to the minimum example below I had also stack height 0 != 1, but I guess that is related, so I didn't reproduce it (mail me if this you need this, too). mport java.lang.reflect.Method; public class StackError { public static void main(String args[]) {} void assertTrue(String msg, boolean b) {} public void testEqualsNull() { StackError one = new StackError(); StackError two = new StackError(); assertTrue("equal", one.equals(two)); // does not work boolean yes = one.equals(two); // works } public boolean equals(Object other) { return true; } } aspect EqualsContract { pointcut equalsCall(Object thisOne, Object otherOne): target(Object+) && target(thisOne) && call(public boolean equals(Object+)) && args(otherOne) && !within(EqualsContract); boolean around(Object thisOne, Object otherOne): equalsCall(thisOne, otherOne) { boolean result = proceed(thisOne, otherOne); Class cls = thisOne.getClass(); String name = cls.getName(); boolean hasHashCode = false; try { Method m = cls.getDeclaredMethod("hashCode", null); String lookFor = "public int " + name + ".hashCode()"; hasHashCode = lookFor.equals(m.toString()); } catch (NoSuchMethodException nsme) {} return result; } } The program does not crash if you comment out the line indicated with the "does not work" comment. Note the line below that (comment "works") does work.

Files changed in fix:
tests/bugs/StackError.java tests/bugs/messyAround/cap/OptionList.java weaver/src/org/aspectj/weaver/bcel/BcelShadow.java weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java