Menu

#564 ProGuard changes the order of implemented interfaces in a class file

v5.1
open-accepted
None
5
2016-06-20
2015-02-11
No

ProGuard changes the order of implemented interfaces in a class file.

Suppose we have a class
class MyClass implements IfA, IfB { ....

ProGuard changes in some cases the class file to
class MyClass implements IfB, IfA

According to the JVM Spec the order of the interface must be preserved:

The Java Virtual Machine Specification Java SE 8 Edition (also 7)
4.1 The ClassFile Structure Page 79
"... CONSTANT_Class_info structure representing an interface that is a direct
superinterface of this class or interface type, in the left-to-right order given in
the source for the type."

The issue could be reproduces with the class file attached:
FormattingServiceFormatterTest$FormatThenDebug.class
and the proguard config:
proguardConfig.pro

All included in the zip file.
Also the disassembled class files before and after Obfuscation.
Version: ProGuard Version 5.1

I think the problematic classes in ProGuard are:
proguard.classfile.editor.ClassElementSorter
proguard.classfile.editor.InterfaceSorter
It looks like that was intentional.

Would it be possible to get an option to switch off the InterfaceSorter via the configuration file?

My code needs the interface ordering to linearize a classhierachy of classes and interfaces, if this is not stable the code will behave differently in the obfuscation and non-obfuscation code.

1 Attachments

Discussion

  • Eric Lafortune

    Eric Lafortune - 2015-02-12

    Thanks for your report. ProGuard indeed sorts interfaces on purpose. I'll consider adding a -D flag to disable it, or maybe add a criterion based on -keep options. For now, you can comment out the line in ClassElementSorter. Note that ProGuard may also remove unused interfaces or merge interfaces that only have a single implementation.

     
  • Eric Lafortune

    Eric Lafortune - 2015-02-12
    • status: open --> open-accepted
    • assigned_to: Eric Lafortune
     
  • Petar Tahchiev

    Petar Tahchiev - 2016-06-20

    Any updates on this? Why do you plan to add a flag to stop this behaviour, when it violates the JVM spec?

     

Log in to post a comment.