ProGuard因ArrayIndexOutOfBoundsException而失败

时间:2014-01-19 09:58:16

标签: java-me proguard

我在构建J2ME应用程序时使用ProGuard。 ProGruard在使用ArrayIndexOutOfBoundsException异常进行优化期间失败(参见(1))。

导致失败的代码是' straintforward' :这是一个将23个字段从一个POJO复制到另一个POJO的方法(参见(2))。另外,当我评论一些get / set语句时,ProGruad不会失败(参见(3))。

(1)ProGruard记录

 [proguard] ProGuard, version 4.3
 [proguard] Reading input...
 [proguard] Reading program jar [...] (filtered)
 [proguard] Reading library jar [.../WTK2.5.2/lib/midpapi21.jar]
 [proguard] Reading library jar [.../WTK2.5.2/lib/cldcapi11.jar]
 [proguard] Reading library jar [.../WTK2.5.2/lib/wma20.jar]
 [proguard] Initializing...
 [proguard] Ignoring unused library classes...
 [proguard]   Original number of library classes: 947
 [proguard]   Final number of library classes:    87
 [proguard] Printing kept classes, fields, and methods...
 [proguard] Shrinking...
 [proguard] Removing unused program classes and class elements...
 [proguard]   Original number of program classes: 223
 [proguard]   Final number of program classes:    189
 [proguard] Inlining subroutines...
 [proguard] Optimizing...
 [proguard] Unexpected error while merging classes:
 [proguard]   Class        = [.../TransactionEntityBuilder]
 [proguard]   Target class = [.../TransactionEntity]
 [proguard]   Exception    = [java.lang.ArrayIndexOutOfBoundsException] (3113)
 [proguard] java.lang.ArrayIndexOutOfBoundsException: 3113
 [proguard]     at proguard.classfile.editor.CodeAttributeComposer.appendInstruction(CodeAttributeComposer.java:184)
 [proguard]     at proguard.classfile.editor.InstructionAdder.visitConstantInstruction(InstructionAdder.java:74)
 [proguard]     at proguard.classfile.instruction.ConstantInstruction.accept(ConstantInstruction.java:161)
 [proguard]     at proguard.classfile.attribute.CodeAttribute.instructionsAccept(CodeAttribute.java:138)
 [proguard]     at proguard.classfile.attribute.CodeAttribute.instructionsAccept(CodeAttribute.java:110)
 [proguard]     at proguard.classfile.editor.AttributeAdder.visitCodeAttribute(AttributeAdder.java:262)
 [proguard]     at proguard.classfile.attribute.CodeAttribute.accept(CodeAttribute.java:101)
 [proguard]     at proguard.classfile.ProgramMethod.attributesAccept(ProgramMethod.java:79)
 [proguard]     at proguard.classfile.editor.MemberAdder.visitProgramMethod(MemberAdder.java:234)
 [proguard]     at proguard.classfile.ProgramMethod.accept(ProgramMethod.java:71)
 [proguard]     at proguard.classfile.ProgramClass.methodsAccept(ProgramClass.java:439)
 [proguard]     at proguard.optimize.peephole.ClassMerger.visitProgramClass0(ClassMerger.java:259)
 [proguard]     at proguard.optimize.peephole.ClassMerger.visitProgramClass(ClassMerger.java:116)
 [proguard]     at proguard.classfile.visitor.ProgramClassFilter.visitProgramClass(ProgramClassFilter.java:52)
 [proguard]     at proguard.classfile.ProgramClass.accept(ProgramClass.java:281)
 [proguard]     at proguard.classfile.LibraryClass.subclassesAccept(LibraryClass.java:370)
 [proguard]     at proguard.classfile.visitor.SubclassTraveler.visitLibraryClass(SubclassTraveler.java:58)
 [proguard]     at proguard.classfile.LibraryClass.accept(LibraryClass.java:248)
 [proguard]     at proguard.classfile.constant.ClassConstant.referencedClassAccept(ClassConstant.java:102)
 [proguard]     at proguard.classfile.visitor.ReferencedClassVisitor.visitClassConstant(ReferencedClassVisitor.java:128)
 [proguard]     at proguard.classfile.constant.ClassConstant.accept(ClassConstant.java:91)
 [proguard]     at proguard.classfile.ProgramClass.superClassConstantAccept(ProgramClass.java:402)
 [proguard]     at proguard.optimize.peephole.HorizontalClassMerger.visitProgramClass(HorizontalClassMerger.java:82)
 [proguard]     at proguard.classfile.ProgramClass.accept(ProgramClass.java:281)
 [proguard]     at proguard.classfile.ClassPool.classesAccept(ClassPool.java:114)
 [proguard]     at proguard.optimize.Optimizer.execute(Optimizer.java:301)
 [proguard]     at proguard.ProGuard.optimize(ProGuard.java:325)
 [proguard]     at proguard.ProGuard.execute(ProGuard.java:114)
 [proguard]     at proguard.ProGuard.main(ProGuard.java:499)

(2)失败的方法

    public static TransactionEntityShadow convertFromLegacy(TransactionEntity legacy) {
        TransactionEntityShadow result = new TransactionEntityShadow(legacy.getService(), legacy.getAliasCode());

        result.setAliasCode                 (legacy.getAliasCode());
        result.setAmount                    (legacy.getAmount());
        result.setBeneficiaryAccountNumber  (legacy.getBeneficiaryAccountNumber());
        result.setBeneficiaryId             (legacy.getBeneficiaryId());
        result.setBeneficiaryIdTypeId       (legacy.getBeneficiaryIdTypeId());
        result.setBeneficiaryMSISDN         (legacy.getBeneficiaryMSISDN());
        result.setBeneficiaryName           (legacy.getBeneficiaryName());
        result.setBeta                      (legacy.getBeta());
        result.setBillContractNumber        (legacy.getBillContractNumber());
        result.setBillNumber                (legacy.getBillNumber());
        result.setBillSecretCode            (legacy.getBillSecretCode());
        result.setContractBeta              (legacy.getContractBeta());
        result.setCustomerKey               (legacy.getCustomerKey());
        result.setFeesAmount                (legacy.getFeesAmount());
        result.setFreeByte1                 (legacy.getFreeByte1());
        result.setFreeByte2                 (legacy.getFreeByte2());
        result.setLanguageIndex             (legacy.getLanguageIndex());
        result.setMerchantCode              (legacy.getMerchantCode());
        result.setMerchantServiceCode       (legacy.getMerchantServiceCode());
        result.setPinDigest                 (legacy.getPinDigest());
        result.setService                   (legacy.getService());
        result.setSessionKey                (legacy.getSessionKey());
        result.setTransactionDate           (legacy.getTransactionDate());

        return result;
    }

(3)评论该方法的某些行将使ProGruad不会失败

    public static TransactionEntityShadow convertFromLegacy(TransactionEntity legacy) {
        TransactionEntityShadow result = new TransactionEntityShadow(legacy.getService(), legacy.getAliasCode());

        result.setAliasCode                 (legacy.getAliasCode());
        result.setAmount                    (legacy.getAmount());
        result.setBeneficiaryAccountNumber  (legacy.getBeneficiaryAccountNumber());
        result.setBeneficiaryId             (legacy.getBeneficiaryId());
        result.setBeneficiaryIdTypeId       (legacy.getBeneficiaryIdTypeId());
        result.setBeneficiaryMSISDN         (legacy.getBeneficiaryMSISDN());
//      result.setBeneficiaryName           (legacy.getBeneficiaryName());
//      result.setBeta                      (legacy.getBeta());
//      result.setBillContractNumber        (legacy.getBillContractNumber());
//      result.setBillNumber                (legacy.getBillNumber());
//      result.setBillSecretCode            (legacy.getBillSecretCode());
//      result.setContractBeta              (legacy.getContractBeta());
        result.setCustomerKey               (legacy.getCustomerKey());
        result.setFeesAmount                (legacy.getFeesAmount());
        result.setFreeByte1                 (legacy.getFreeByte1());
        result.setFreeByte2                 (legacy.getFreeByte2());
        result.setLanguageIndex             (legacy.getLanguageIndex());
        result.setMerchantCode              (legacy.getMerchantCode());
        result.setMerchantServiceCode       (legacy.getMerchantServiceCode());
        result.setPinDigest                 (legacy.getPinDigest());
        result.setService                   (legacy.getService());
        result.setSessionKey                (legacy.getSessionKey());
        result.setTransactionDate           (legacy.getTransactionDate());

        return result;
    }

2 个答案:

答案 0 :(得分:0)

看起来它是ProGuard 4.3版中的错误/限制。我已经转到4.4版本,问题就解决了。

答案 1 :(得分:0)

在你的proguard中使用-dontoptimize