androiddexjava-bytecode-asmandroid-r8

Int switch error when inject code generator with switch case in java code


Caused by: java.lang.AssertionError at com.android.tools.r8.ir.code.IntSwitch.valid(IntSwitch.java:67) at com.android.tools.r8.ir.code.IntSwitch.(IntSwitch.java:35) at com.android.tools.r8.ir.conversion.IRBuilder.createSwitch(IRBuilder.java:1922) at com.android.tools.r8.ir.conversion.IRBuilder.addSwitch(IRBuilder.java:1886) at com.android.tools.r8.cf.code.CfSwitch.buildIR(CfSwitch.java:101) at com.android.tools.r8.ir.conversion.CfSourceCode.build(CfSourceCode.java:581) Caused by: com.android.builder.dexing.DexArchiveBuilderException: Error while dexing.

java sample

 public IFactory getInjectMap(String var1) {
          byte var2 = -1;
          switch(var1.hashCode()) {
          case 2011670744:
             if (var1.equals("xxx.xxx.xxx.xxx")) {
                var2 = 0;
             }
             break;
          case -1047643106:
             if (var1.equals("xxx.xxx.xxx.xxx")) {
                var2 = 1;
             }
             break;
          }
    
          switch(var2) {
          case 0:
             var2 = (byte)(new xxxxFactory());
             break;
          case 1:
             var2 = (byte)(new xxxxFactory());
             break;
          default:
             var2 = (byte)null;
          }
    
          return var2;
       }
    }

Solution

  • The assertion error you hit is validating that the values in the lookupswitch instruction is ordered, as mandated by the JVM specification. This indicate that the generated bytecode is not following the specification. Does this code run on the JVM?

    This is also reported as https://issuetracker.google.com/200284898#comment6.