# J2ME, dead code not removed

This topic is 4481 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi again everyone. I've been using a 'debug' class with a static final boolean so i can switch between outputting debug data (simple println) and not. The problem is that when I set the debug boolean to false it seems as though code that shold be removed, since the boolean is false and the code can never be reached, is not removed. Heres some code to explain a little better.
public class Debug {
public static final boolean ON = false;
}


and in my main code I try 'switching' by doing this:
if (Debug.ON) {
System.out.println("The code is still here!");
}


Ok thats fairly standard stuff as far as I'm aware, but the code that should be removed remains after compilation and obfuscation using Proguard. On a related note, in an attempt to figure this out myself (if nobody has the answer) how do I use the 'argument' nested element in the WTKObfuscate task in Antenna? I would like to use the arguments -printusage and/or -whyareyoukeeping to try to get more information about what Proguard is doing while shrinking/obfuscating. Thanks for reading!

##### Share on other sites
This won't work, unfortunately. I'm not sure why, but it'd save us a lot of work, indeed.

Your only option is probably using a source code preprocessor.

Here's how you use arguments in wtkobfusacte:

##### Share on other sites
Ok, that helps a lot, nmi! (rating++ :)

Then it probably means that wtkbuild doesn't optimize (I think I remember it didn't).

However, we now use the javac task here and our own packaging, so probably that's why dead code blocks never came up again as a topic - they were silently optimized away and we had no incentive to look for them.

Could you do me a favor, nmi? Compile the classes with source compatibility 1.2 or lower, and class file compatibility Java 1.1 ... this is what's used for J2ME.

##### Share on other sites
you may "force" the wtkbuild task to do optimization using optimize="on" (which is, actually, a parameter of javac). by default, optimization is off in javac task.

##### Share on other sites
Hey guys,

I have to explain myself here, and perhaps even apologise.

First of all we suffered a power cut yesterday which was why I didnt reply earlier.

My 'problem' didn't actually exist, my Debug java file, with ON set to false, was being overwritten by a backup Debug file which was being copied during the build process, and yes you guessed it, On was set to true. So its all my fault guys, I'm sorry. :(

Hopefully this hasn't been a complete waste of everyones time, at least I learned to be more careful in future.

Thanks for all your efforts to help and I apologise once more!

Cheers

##### Share on other sites
Why not just use the Antenna preprocessor? Then you don't need to worry about Debug classes.

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 11
• 15
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633354
• Total Posts
3011487
• ### Who's Online (See full list)

There are no registered users currently online

×