title: Android proguard obfuscated code is causing NullPointerException when it really shouldn't be
body: <p>I have distributed an application on the Android Marketplace.  I am getting error reports back in from a small handful of users (maybe 2%) where they are getting NullPointerExceptions where it doesn't make logical sense.  </p>
  
  <p>I have never been able to replicate this myself.  The code is relatively straightforward and is a common code path that EVERY user has to follow.  I've actually taken every separate line of code that could possibly be creating the NPE and wrapped it in a try-catch block and throw a custom runtime exception, but I'm still getting NullPointerException errors not caught.</p>
  
  <p>At this point, the only thing I can imagine it would be is something related to my Proguard obfuscation.  I have seen some other article talking about taking out the -overloadaggressively option if you notice odd behavior, but as far as I can tell, I'm not using that option.</p>
  
  <p>Has anybody else experienced mysterious NPEs using android and proguard.  Are there any other settings people can recommend to dial down the optimizations that might be causing this issue?</p>
  
  <p>Any other ideas?</p>
  
  <p>For reference, here is the unobfuscated function that is getting the NPE:</p>
  
  <pre><code>public MainMenuScreen(final HauntedCarnival game) {
      super(game);
  
      game.startMusic("data/music/intro.mp3");
  
      stage = new Stage(Screen.SCREEN_WIDTH, Screen.SCREEN_HEIGHT,true);
      stage.addActor(new Image("background", Assets.mainMenuBackground));
      Image title = new Image("title", Assets.mainMenuTitle);
      title.x = 0;
      title.y = 340;
      resetEyeBlink();
      stage.addActor(title);
      dispatcher.registerInputProcessor(stage);
      settings = game.getSettings();
  
      eyeBlinkImage = new Image("eyeBlink", Assets.eyeBlink);
      if (settings.getPlayers().isEmpty()) {
          settings.addPlayer("Player One");
          settings.save(game);
      }
      setupContinue();
  
  
  }
  </code></pre>
  
  <p>So the only possibilities I can see are game, dispatcher and settings.</p>
  
  <p>game gets set via this code in another class.  game is a final variable in that other class:</p>
  
  <pre><code>game.setScreen(new MainMenuScreen(game));
  </code></pre>
  
  <p>dispatcher gets set within in the call to super above.</p>
  
  <p>getSettings() returns a settings object that gets set at the very start of the application, is private and never gets unset.  Its also used before this method several times.</p>
  
  <p>There are not auto-boxing primitives.</p>
  
  <p>here is the proguard config:</p>
  
  <pre><code>-optimizationpasses 5
  -dontusemixedcaseclassnames
  -dontskipnonpubliclibraryclasses
  -dontpreverify
  -verbose
  -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
  
  -keepattributes Signature
  
  -keep public class com.alkilabs.hauntedcarnival.settings.Settings
  -keep public class com.alkilabs.hauntedcarnival.settings.Settings {
      *;
  }
  -keep public class com.alkilabs.hauntedcarnival.settings.Player
  -keep public class com.alkilabs.hauntedcarnival.settings.Player {
      *;
  }
  -keepnames public class com.alkilabs.hauntedcarnival.world.World
  -keepnames public class * extends com.alkilabs.hauntedcarnival.world.upgrades.Upgrade
  -keepnames public class * extends com.alkilabs.hauntedcarnival.world.achievments.Achievement
  
  -keepnames public class com.alkilabs.hauntedcarnival.world.monsters.MonsterType
  -keepclassmembers class * extends com.alkilabs.hauntedcarnival.world.monsters.Monster {
      public &lt;init&gt;(com.alkilabs.hauntedcarnival.world.monsters.MonsterType, java.lang.Integer, com.alkilabs.hauntedcarnival.world.World);
  }
  
  -keepnames public class com.alkilabs.hauntedcarnival.world.items.ItemType
  -keepclassmembers class * extends com.alkilabs.hauntedcarnival.world.items.Item {
      public &lt;init&gt;(com.alkilabs.hauntedcarnival.world.World, java.lang.Integer, java.lang.Integer);
  }
  
  
  -keep public class * extends android.app.Activity
  -keep public class * extends android.app.Application
  -keep public class * extends android.app.Service
  -keep public class * extends android.content.BroadcastReceiver
  -keep public class * extends android.content.ContentProvider
  -keep public class * extends android.app.backup.BackupAgentHelper
  -keep public class * extends android.preference.Preference
  
  -dontwarn com.badlogic.gdx.scenes.scene2d.ui.utils.DesktopClipboard
  -dontwarn com.badlogic.gdx.utils.JsonWriter
  -dontwarn com.badlogic.gdx.utils.XmlWriter
  
  -keepclasseswithmembernames class * {
      native &lt;methods&gt;;
  }
  
  -keepclasseswithmembers class * {
      public &lt;init&gt;(android.content.Context, android.util.AttributeSet);
  }
  
  -keepclasseswithmembers class * {
      public &lt;init&gt;(android.content.Context, android.util.AttributeSet, int);
  }
  
  -keepclassmembers class * extends android.app.Activity {
     public void *(android.view.View);
  }
  
  -keepclassmembers enum * {
      public static **[] values();
      public static ** valueOf(java.lang.String);
  }
  
  -keep class * implements android.os.Parcelable {
    public static final android.os.Parcelable$Creator *;
  }
  </code></pre>