Sundarrajk's Weblog

PMD – Android Rules

Posted on: September 28, 2011


This is the twenty fourth installment of explanation of PMD rules covering some Android rules.

Android Rules

These rules deal with the Android SDK, mostly related to best practices. To get better results, make sure that the auxclasspath is defined for type resolution to work.

CallSuperFirst

Super should be called at the start of the method

Example

public class DummyActivity extends Activity {
    public void onCreate(Bundle bundle) {
     // missing call to super.onCreate(bundle)
     foo();
    }
   }

CallSuperLast

Super should be called at the end of the method

Example

public class DummyActivity extends Activity {
    public void onPause() {
     foo();
     // missing call to super.onPause()
    }
   }

ProtectLogD

Log.d calls should be protected by checking Config.LOGD first

Example

public class DummyActivity extends Activity {
    public void foo() {
     Log.d("TAG", "msg1"); // Bad
 
     bar();
 
     if (Config.LOGD) Log.d("TAG", "msg1"); // Good
    }
   }

ProtectLogV

Log.v calls should be protected by checking Config.LOGV first

Example

public class DummyActivity extends Activity {
    public void foo() {
     Log.v("TAG", "msg1"); // Bad
 
     bar();
 
     if (Config.LOGV) Log.v("TAG", "msg1"); // Good
    }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Categories

Advertisements
%d bloggers like this: