#437 IllegalArgumentException: Stacks have different current size

v4.7
closed-fixed
5
2013-03-20
2012-02-15
Max
No

0 down vote favorite
share [g+] share [fb] share [tw]

Proguard is crashing with "Proguard returned with error code 1", and this crash in the console:

java.lang.IllegalArgumentException: Stacks have different current sizes [0] and [1]
at proguard.evaluation.Stack.generalize(Stack.java:125)
at proguard.evaluation.TracedStack.generalize(TracedStack.java:140)
at proguard.optimize.evaluation.PartialEvaluator.evaluateSingleInstructionBlock(PartialEvaluator.java:683)
at proguard.optimize.evaluation.PartialEvaluator.evaluateInstructionBlock(PartialEvaluator.java:587)
at proguard.optimize.evaluation.PartialEvaluator.visitExceptionInfo(PartialEvaluator.java:1078)
at proguard.classfile.visitor.ExceptionHandlerFilter.visitExceptionInfo(ExceptionHandlerFilter.java:67)
at proguard.classfile.attribute.CodeAttribute.exceptionsAccept(CodeAttribute.java:186)
at proguard.optimize.evaluation.PartialEvaluator.evaluateExceptionHandlers(PartialEvaluator.java:1018)
at proguard.optimize.evaluation.PartialEvaluator.evaluateInstructionBlockAndExceptionHandlers(PartialEvaluator.java:567)
at proguard.optimize.evaluation.PartialEvaluator.visitCodeAttribute0(PartialEvaluator.java:264)
at proguard.optimize.evaluation.PartialEvaluator.visitCodeAttribute(PartialEvaluator.java:181)
at proguard.optimize.evaluation.LivenessAnalyzer.visitCodeAttribute(LivenessAnalyzer.java:205)
at proguard.optimize.evaluation.VariableOptimizer.visitCodeAttribute(VariableOptimizer.java:105)
at proguard.classfile.attribute.CodeAttribute.accept(CodeAttribute.java:101)
at proguard.classfile.ProgramMethod.attributesAccept(ProgramMethod.java:79)
at proguard.classfile.attribute.visitor.AllAttributeVisitor.visitProgramMember(AllAttributeVisitor.java:95)
at proguard.classfile.util.SimplifiedVisitor.visitProgramMethod(SimplifiedVisitor.java:91)
at proguard.classfile.ProgramMethod.accept(ProgramMethod.java:71)
at proguard.classfile.ProgramClass.methodsAccept(ProgramClass.java:504)
at proguard.classfile.visitor.AllMethodVisitor.visitProgramClass(AllMethodVisitor.java:47)
at proguard.classfile.ProgramClass.accept(ProgramClass.java:346)
at proguard.classfile.ClassPool.classesAccept(ClassPool.java:116)
at proguard.optimize.Optimizer.execute(Optimizer.java:833)
at proguard.ProGuard.optimize(ProGuard.java:306)
at proguard.ProGuard.execute(ProGuard.java:115)
at proguard.ProGuard.main(ProGuard.java:492)

stack overflow link: http://stackoverflow.com/questions/9282011/proguard-illegalargumentexception-stacks-have-different-current-sizes/9286733#9286733

I have narrowed it down to a try catch block for an IOException. If I comment out that try catch block then it shows this error for another IOException try catch block elsewhere in the app. If I comment that one out, then it successfully builds.

So in both places proguard seems to be crashing on an IOException try catch block. These blocks have been in the code in previous builds that went through proguard without any trouble before.

Also, there are other IOException catch blocks that don't give any errors.

I tried this with proguard 4.5, 4.6, and 4.7 and all failed.

A further update: I was able to work around this by commenting out the code inside of the offending IOExeceptions try catch block. Specifically it seemed to be the catch block code that was the problem. In each case it was one line of code that called another method that the exception was passed to. Beyond that it was hard to determine what was causing the problem.

Unfortunately, I cannot narrow this down enough to provide a small code sample. Hope this is enough to work off of. Thanks for an awesome tool.

Discussion

  • Eric Lafortune
    Eric Lafortune
    2012-02-15

    • assigned_to: nobody --> lafortune
    • priority: 5 --> 7
    • status: open --> open-remind
     
  • Eric Lafortune
    Eric Lafortune
    2012-02-15

    Thanks for the report. Without an example, it's hard to tell. The upcoming version 4.8 beta1 has some fixes in this area, so it would be helpful if you could try that when it's released and report your findings.

     
  • Dan Cartoon
    Dan Cartoon
    2013-02-11

    I actually just ran into this with ProGuard 4.7 and ProGuard 4.9 beta2. I'll include the stacks in two separate comments to keep this from getting too cluttered:

    In ProGuard 4.7, the exception is actually a NullPointerException:

    [proguard] Unexpected error while evaluating instruction:
    [proguard] Class = [gamook/framework/utils/BitmapUtil]
    [proguard] Method = [overlayBitmap(Landroid/graphics/Bitmap;Landroid/graphics/Bitmap;F)Landroid/graphics/Bitmap;

    [proguard] Instruction = [86] aload v8
    [proguard] Exception = [java.lang.NullPointerException] (null)
    [proguard] Unexpected error while performing partial evaluation:
    [proguard] Class = [gamook/framework/utils/BitmapUtil]
    [proguard] Method = [overlayBitmap(Landroid/graphics/Bitmap;Landroid/graphics/Bitmap;F)Landroid/graphics/Bitmap;

    [proguard] Exception = [java.lang.NullPointerException] (null)

    BUILD FAILED
    :\Codebase\Gamook\Trunk\Android\src\build\build.xml:934: java.lang.NullPointerException
    at proguard.evaluation.Variables.aload(Variables.java:263)
    at proguard.evaluation.Processor.visitVariableInstruction(Processor.java:675)
    at proguard.classfile.instruction.VariableInstruction.accept(VariableInstruction.java:306)
    at proguard.optimize.evaluation.PartialEvaluator.evaluateSingleInstructionBlock(PartialEvaluator.java:753)
    at proguard.optimize.evaluation.PartialEvaluator.evaluateInstructionBlock(PartialEvaluator.java:602)
    at proguard.optimize.evaluation.PartialEvaluator.evaluateInstructionBlockAndExceptionHandlers(PartialEvaluator.j
    va:560)
    at proguard.optimize.evaluation.PartialEvaluator.evaluateSubroutine(PartialEvaluator.java:924)
    at proguard.optimize.evaluation.PartialEvaluator.evaluateSingleInstructionBlock(PartialEvaluator.java:870)
    at proguard.optimize.evaluation.PartialEvaluator.evaluateInstructionBlock(PartialEvaluator.java:602)
    at proguard.optimize.evaluation.PartialEvaluator.evaluateInstructionBlockAndExceptionHandlers(PartialEvaluator.j
    va:560)
    at proguard.optimize.evaluation.PartialEvaluator.evaluateSubroutine(PartialEvaluator.java:924)
    at proguard.optimize.evaluation.PartialEvaluator.evaluateSingleInstructionBlock(PartialEvaluator.java:870)
    at proguard.optimize.evaluation.PartialEvaluator.evaluateInstructionBlock(PartialEvaluator.java:602)
    at proguard.optimize.evaluation.PartialEvaluator.evaluateInstructionBlockAndExceptionHandlers(PartialEvaluator.j
    va:560)
    at proguard.optimize.evaluation.PartialEvaluator.visitCodeAttribute0(PartialEvaluator.java:264)
    at proguard.optimize.evaluation.PartialEvaluator.visitCodeAttribute(PartialEvaluator.java:181)
    at proguard.optimize.info.ParameterUsageMarker.visitCodeAttribute(ParameterUsageMarker.java:176)
    at proguard.classfile.attribute.CodeAttribute.accept(CodeAttribute.java:101)
    at proguard.classfile.ProgramMethod.attributesAccept(ProgramMethod.java:79)
    at proguard.optimize.info.ParameterUsageMarker.visitProgramMethod(ParameterUsageMarker.java:136)
    at proguard.optimize.OptimizationInfoMemberFilter.visitProgramMethod(OptimizationInfoMemberFilter.java:81)
    at proguard.classfile.ProgramMethod.accept(ProgramMethod.java:71)
    at proguard.classfile.ProgramClass.methodsAccept(ProgramClass.java:504)
    at proguard.classfile.visitor.AllMethodVisitor.visitProgramClass(AllMethodVisitor.java:47)
    at proguard.classfile.ProgramClass.accept(ProgramClass.java:346)
    at proguard.classfile.ClassPool.classesAccept(ClassPool.java:116)
    at proguard.optimize.Optimizer.execute(Optimizer.java:341)
    at proguard.ProGuard.optimize(ProGuard.java:306)
    at proguard.ProGuard.execute(ProGuard.java:115)
    at proguard.ant.ProGuardTask.execute(ProGuardTask.java:311)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
    at com.android.ant.IfElseTask.execute(IfElseTask.java:120)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:392)
    at org.apache.tools.ant.Target.performTasks(Target.java:413)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.apache.tools.ant.Main.runBuild(Main.java:811)
    at org.apache.tools.ant.Main.startAnt(Main.java:217)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

    I've posted a snippet of the code here: https://gist.github.com/dcartoon/4758703

    (Sorry, having trouble formatting code in SourceForge)

    The critical part here is within the nested finally block. If we move "resizedOverlay=null" out of the nested finally and remove the nested finally, that fixes the exception.

    I tried copying the file containing this code into a new project that I could post publicly to repro the issue, but have not had any luck getting ProGuard to fail that way.

     
    Last edit: Dan Cartoon 2013-02-12
  • Dan Cartoon
    Dan Cartoon
    2013-02-12

    Here's the code that causes an IllegalArgumentException with ProGuard 4.9 beta 2: https://gist.github.com/dcartoon/4758842

    [proguard] Unexpected error while performing partial evaluation:
    [proguard] Class = [gamook/framework/graphics/NetworkImageStreamWorker]
    [proguard] Method = [loadBitmapFromFile(Lgamook/framework/graphics/INetworkImageType;Ljava/lang/String;Landroid/
    graphics/Bitmap;)Landroid/graphics/Bitmap;]

    [proguard] Exception = [java.lang.IllegalArgumentException] (Stacks have different current sizes [0] and [2])

    BUILD FAILED
    c:\Codebase\Gamook\Trunk\Android\src\build\build.xml:934: java.lang.IllegalArgumentException: Stacks have different curr
    ent sizes [0] and [2]
    at proguard.evaluation.Stack.generalize(Stack.java:125)
    at proguard.evaluation.TracedStack.generalize(TracedStack.java:140)
    at proguard.optimize.evaluation.PartialEvaluator.evaluateSingleInstructionBlock(PartialEvaluator.java:683)
    at proguard.optimize.evaluation.PartialEvaluator.evaluateInstructionBlock(PartialEvaluator.java:602)
    at proguard.optimize.evaluation.PartialEvaluator.evaluateInstructionBlockAndExceptionHandlers(PartialEvaluator.j
    ava:560)
    at proguard.optimize.evaluation.PartialEvaluator.visitCodeAttribute0(PartialEvaluator.java:264)
    at proguard.optimize.evaluation.PartialEvaluator.visitCodeAttribute(PartialEvaluator.java:181)
    at proguard.optimize.info.ParameterUsageMarker.visitCodeAttribute(ParameterUsageMarker.java:176)
    at proguard.classfile.attribute.CodeAttribute.accept(CodeAttribute.java:101)
    at proguard.classfile.ProgramMethod.attributesAccept(ProgramMethod.java:79)
    at proguard.optimize.info.ParameterUsageMarker.visitProgramMethod(ParameterUsageMarker.java:136)
    at proguard.optimize.OptimizationInfoMemberFilter.visitProgramMethod(OptimizationInfoMemberFilter.java:81)
    at proguard.classfile.ProgramMethod.accept(ProgramMethod.java:71)
    at proguard.classfile.ProgramClass.methodsAccept(ProgramClass.java:504)
    at proguard.classfile.visitor.AllMethodVisitor.visitProgramClass(AllMethodVisitor.java:47)
    at proguard.classfile.ProgramClass.accept(ProgramClass.java:346)
    at proguard.classfile.ClassPool.classesAccept(ClassPool.java:125)
    at proguard.optimize.Optimizer.execute(Optimizer.java:341)
    at proguard.ProGuard.optimize(ProGuard.java:307)
    at proguard.ProGuard.execute(ProGuard.java:116)
    at proguard.ant.ProGuardTask.execute(ProGuardTask.java:316)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
    at com.android.ant.IfElseTask.execute(IfElseTask.java:120)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:392)
    at org.apache.tools.ant.Target.performTasks(Target.java:413)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.apache.tools.ant.Main.runBuild(Main.java:811)
    at org.apache.tools.ant.Main.startAnt(Main.java:217)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

     
  • Eric Lafortune
    Eric Lafortune
    2013-02-12

    Thanks for the report, Dan. I actually get yet another error (Unsupported stack size increment [2]). Could you mail me the original compiled class NetworkImageStreamWorker.class? Otherwise, which compiler and which target JDK are you using?

     
  • Eric Lafortune
    Eric Lafortune
    2013-02-13

    Thanks for the details, Dan. The problem should now be fixed for the upcoming ProGuard 4.9 beta3. Please reopen this report otherwise. Note that you can clean up the code a lot; setting these local variables to null doesn't seem to serve any purpose.

     
  • Eric Lafortune
    Eric Lafortune
    2013-02-13

    • status: open-remind --> open-fixed
     
  • Eric Lafortune
    Eric Lafortune
    2013-03-20

    • Status: open-fixed --> closed-fixed
    • Priority: 7 --> 5