-
Notifications
You must be signed in to change notification settings - Fork 464
Open
Description
With Proguard 7.3+ I was trying to optimise essentially the following code:
public void load(CustomProperties prop) {
this.field = prop.getValue("field", (CustomValue) null); // doesn't appear to work!
}
with CustomProperties
having two methods with the same name, but different parameters:
public CustomValue getValue(String key, CustomValue def) {
if (containsKey(key)) {
return requireValue(key);
} else {
return def;
}
}
public CustomValue getValue(String key, String def) {
if (containsKey(key)) {
return requireValue(key);
} else {
return new CustomValue(def);
}
}
Without the (CustomValue) null
cast in function()
, the code would not compile, as the method call was ambiguous.
However trying to optimise with Proguard out of the box was failing with:
Unexpected error while inlining method:
Target class = [org/.../CustomClassName]
Target method = [load(...)V]
Exception = [java.lang.IllegalArgumentException] (Invalid instruction offset [691] in code fragment at level 0)
java.lang.IllegalArgumentException: Invalid instruction offset [691] in code fragment at level 0
at proguard.classfile.editor.CodeAttributeComposer.newInstructionOffset(CodeAttributeComposer.java:1159) ~[proguard-core-9.0.3.jar:9.0.3]
at proguard.classfile.editor.CodeAttributeComposer.visitTypeArgumentTargetInfo(CodeAttributeComposer.java:1069) ~[proguard-core-9.0.3.jar:9.0.3]
at proguard.classfile.attribute.annotation.target.TypeArgumentTargetInfo.accept(TypeArgumentTargetInfo.java:80) ~[proguard-core-9.0.3.jar:9.0.3]
at proguard.classfile.attribute.annotation.TypeAnnotation.targetInfoAccept(TypeAnnotation.java:101) ~[proguard-core-9.0.3.jar:9.0.3]
at proguard.classfile.editor.CodeAttributeComposer.visitTypeAnnotation(CodeAttributeComposer.java:1037) ~[proguard-core-9.0.3.jar:9.0.3]
If instead I remove the public CustomValue getValue(String key, String def)
method in CustomProperties
, and remove the (CustomValue) null
cast to disambiguate the method call - Proguard seems to work fine!
public void load(CustomProperties prop) {
this.field = prop.getValue("field", null); // now works!
}
Tried with Gradle + Proguard 7.3, 7.5, 7.7.
Gradle: 7.3
Kotlin: 1.5.31
Groovy: 3.0.9
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 17 (Oracle Corporation 17+35-2724)
OS: Windows 10 10.0 amd64