Since: PMD 4.2.5
Super should be called at the start of the method
//MethodDeclaration[MethodDeclarator[ @Image='onCreate' or @Image='onConfigurationChanged' or @Image='onPostCreate' or @Image='onPostResume' or @Image='onRestart' or @Image='onRestoreInstanceState' or @Image='onResume' or @Image='onStart' ]] /Block[not( (BlockStatement[1]/Statement/StatementExpression/PrimaryExpression[./PrimaryPrefix[@SuperModifier='true']]/PrimarySuffix[@Image= ancestor::MethodDeclaration/MethodDeclarator/@Image]))] [ancestor::ClassOrInterfaceDeclaration[ExtendsList/ClassOrInterfaceType[ typeof(@Image, 'android.app.Activity', 'Activity') or typeof(@Image, 'android.app.Application', 'Application') or typeof(@Image, 'android.app.Service', 'Service') ]]]
public class DummyActivity extends Activity { public void onCreate(Bundle bundle) { // missing call to super.onCreate(bundle) foo(); } }
Since: PMD 4.2.5
Super should be called at the end of the method
//MethodDeclaration[MethodDeclarator[ @Image='finish' or @Image='onDestroy' or @Image='onPause' or @Image='onSaveInstanceState' or @Image='onStop' or @Image='onTerminate' ]] /Block/BlockStatement[last()] [not(Statement/StatementExpression/PrimaryExpression[./PrimaryPrefix[@SuperModifier='true']]/PrimarySuffix[@Image= ancestor::MethodDeclaration/MethodDeclarator/@Image])] [ancestor::ClassOrInterfaceDeclaration[ExtendsList/ClassOrInterfaceType[ typeof(@Image, 'android.app.Activity', 'Activity') or typeof(@Image, 'android.app.Application', 'Application') or typeof(@Image, 'android.app.Service', 'Service') ]]]
public class DummyActivity extends Activity { public void onPause() { foo(); // missing call to super.onPause() } }
Since: PMD 4.2.6
Use Environment.getExternalStorageDirectory() instead of "/sdcard"
//Literal[starts-with(@Image,'"/sdcard')]
public class MyActivity extends Activity { protected void foo() { String storageLocation = "/sdcard/mypackage"; // hard-coded, poor approach storageLocation = Environment.getExternalStorageDirectory() + "/mypackage"; // preferred approach } }