proguard icon indicating copy to clipboard operation
proguard copied to clipboard

Empty class is not removed if instance with static modifier is used.

Open Klayflash opened this issue 6 years ago • 4 comments

I'm trying to remove logging code but it cannot be removed totally. For example, empty "LogObject" class is present in a proguard's output. If "s_log" is commented out then "LogObject" class is also removed.

How to remove empty class?

proguardEmpyClassRemoving.zip

Note: I've used jadx-gui tool to view proguard output.

Klayflash avatar Oct 17 '19 10:10 Klayflash

If local variable is used then the class is removed.

Klayflash avatar Oct 17 '19 16:10 Klayflash

In this case you have code like that:

      if ( s_log == null ) {
        s_log = new LogObject("Id2");
      }

So ProGuard is not able to remove the field s_log as its also accessed for reading (the if (s_log == null) ).

As the field is kept and assigned with a LogObject class, the class itself is also kept.

netomi avatar Nov 20 '19 10:11 netomi

Proguard output is

        if (s_log == null) {
            s_log = new LogObject();
        }

and LogObject is empty class. So, these 3 lines is no operation. Therefore they should be removed. ?

Klayflash avatar Nov 20 '19 19:11 Klayflash

Proguard has an optimization to remove write-only fields. In this case the field is accessed as well (null check), so its not removed.

That would actually be a good improvement, but its currently not supported.

netomi avatar Nov 20 '19 19:11 netomi