AppPerfect

Java OOP Rules

Rules available in this category:

  1. Avoid_redundant_interface_implementations
  2. Avoid_initialising_constant_fields_with_non_static_final_values
  3. Field_value_is_always_constant_null
  4. Declare_methods_not_using_instance_members_static
  5. Avoid_JavaBeans_style_of_construction
  6. Avoid_calling_equals_of_Object_on_Arrays
  7. Remove_System_print_or_println_statements
  8. Avoid_this_instanceof
  9. Do_not_hide_inherited_fields
  10. Override_equals_if_overriding_compareTo
  11. Avoid_abstract_modifier_with_interface
  12. Do_not_hide_inherited_static_methods
  13. Always_call_super_constructor_explicitly
  14. Declare_only_private_constructors_in_utility_classes
  15. Avoid_exception_as_flow_control
  16. Do_not_expose_collection_type_fields
  17. Avoid_returning_internal_array
  18. Avoid_deep_inheritance_hierarchy
  19. Always_declare_instance_fields_private
  20. Do_not_override_private_methods
  21. Always_declare_constructors_protected_for_abstract_class
  22. Make_readResolve_writeReplace_protected_or_public
  23. Always_override_equals_with_same_signature
  24. Avoid_suspicious_version_of_hashcode
  25. Provide_private_default_constructor_in_utility_classes
  26. Avoid_redundant_finalizers
  27. Avoid_synchronize_on_lock_implementation
  28. Avoid_misleading_class_name
  29. Use_interface_references_to_collection
  30. Avoid_instanceof_checks_in_catch_clause
  31. Avoid_nested_inner_classes
  32. Avoid_empty_body_for_implemented_methods
  33. Avoid_abstract_class_without_abstract_method
  34. Do_not_override_nonabstract_methods_with_abstract_methods
Rule 1: Avoid_redundant_interface_implementations

Severity:  Medium
Rule:  Avoid declaring that the class implements an interface which is already implemented by its superclass.
Reason:  Avoid declaring that the class implements an interface which is already implemented by its superclass.

Usage Example: 

interface MyInterface
{
void aMethod();
}

public class SuperClass implements MyInterface
{
public void aMethod()
{
//...
}

//...
}

class SubClass extends SuperClass implements MyInterface //VIOLATION
{
//....
}

Should be written as:

interface MyInterface
{
void aMethod();
}

public class SuperClass implements MyInterface
{
public void aMethod()
{
//...
}

//...
}

class SubClass extends SuperClass // CORRECTION
{
//....
}

Reference:  Reference not available.

Rule 2: Avoid_initialising_constant_fields_with_non_static_final_values

Severity:  Medium
Rule:  It is preferrable to initialise constant fields with constant literals to avoid confusion.
Reason:  It is preferrable to initialise constant fields with constant literals to avoid confusion.

Usage Example: 

public class AvoidInitialisingConstantFieldsWithNonStaticFinalValues 
{
 static int v1 = 7;
 static final int v2 = v1 + 1; // VIOLATION
}

Should be written as:

public class AvoidInitialisingConstantFieldsWithNonStaticFinalValues 
{
 static int v1 = 7;
 static final int v2 = 8; // CORRECTION
}

Reference:  No references available.

Rule 3: Field_value_is_always_constant_null

Severity:  Medium
Rule:  The field value is always null. Check for errors, or remove if it is useless.
Reason:  The field value is always null. Check for errors, or remove if it is useless.

Usage Example: 

public class Test
{
Object b; // VIOLATION

Test()
{
b = null;
}

public void aMethod()
{
if (b != null)
{
b.toString();
}
}
}

Should be written as:


		

Reference:  No references available.

Rule 4: Declare_methods_not_using_instance_members_static

Severity:  Low
Rule:  Redeclare methods as static if not using instance class members.
Reason:  Redeclare methods as static if not using instance class members.

Usage Example: 

package com.rule;

public class Declare_methods_not_using_instance_members_static_violation 
{
//...

public double mean(int[] p)// Violation 
{
int sum = 0;  // sum of all the elements
for (int i=0; i<p.length; i++) 
{
sum += p[i];
}
return ((double)sum) / p.length;

}

Should be written as:

package com.rule;

public class Declare_methods_not_using_instance_members_static_correction
{
//...

public static double mean(int[] p)// Correction 
{
int sum = 0;  // sum of all the elements
for (int i=0; i<p.length; i++) 
{
sum += p[i];
}
return ((double)sum) / p.length;

}

Reference:  http://leepoint.net/notes-java/flow/methods/50static-methods.html

Rule 5: Avoid_JavaBeans_style_of_construction

Severity:  Medium
Rule:  Avoid JavaBeans style of construction.
Reason:  Avoid JavaBeans style of construction.

Usage Example: 

package com.rule;
public class Avoid_JavaBeans_style_of_construction_violation // VIOLATION
{
private int i;
public Avoid_JavaBeans_style_of_construction_violation()
{
}
public void setI(int ii)
{
i = ii;
}
public static void main(String[] args)
{
Avoid_JavaBeans_style_of_construction_violation a = new Avoid_JavaBeans_style_of_construction_violation();
a.setI(0);
}
}

Should be written as:

package com.rule;
public class Avoid_JavaBeans_style_of_construction_correction // CORRECTION
{
private int i;
public Avoid_JavaBeans_style_of_construction_violation(int ii)
{
i = ii;
}
public void setI(int ii)
{
i = ii;
}
public static void main(String[] args)
{
Avoid_JavaBeans_style_of_construction_correction a = new Avoid_JavaBeans_style_of_construction_correction(0);
}
}

Reference:  http://www.javapractices.com/Topic84.cjp

Rule 6: Avoid_calling_equals_of_Object_on_Arrays

Severity:  High
Rule:  Avoid calling equals() of java.lang.Object on Arrays.
Reason:  Avoid calling equals() of java.lang.Object on Arrays.

Usage Example: 

package com.rule;

public class Avoid_calling_equals_of_Object_on_Arrays_violation
{
public void foo(String str1[], String str2[])
{
if(str1.equals(str2))  // Violation
{
//...
}
}
}

Should be written as:

package com.rule;
import java.util.Arrays;

public class Avoid_calling_equals_of_Object_on_Arrays_correction
{
public void foo(String str1[], String str2[])
{
if(java.util.Arrays.equals(str1,str2)) // Correction 
{
//...
}
}
}

Reference:  Reference not available.

Rule 7: Remove_System_print_or_println_statements

Severity:  Low
Rule:  All debugging statements should be cleaned up before the product is released.
Reason:  All debugging statements should be cleaned up before the product is released.

Usage Example: 

public class MyClass
{

public int getMax(int i, int j, int default_num) 
{
int result = default_num;
if (i >= 0 && i > j) 
{
 result = i;

else if (j >= 0 && j >= i) 
{
  result = j;
}
System.out.println("result is : " + result); // VIOLATION
return result;
 }

}

Should be written as:

public class MyClass
{

public int getMax(int i, int j, int default_num) 
{
int result = default_num;
if (i >= 0 && i > j) 
{
 result = i;

else if (j >= 0 && j >= i) 
{
  result = j;
}
// CORRECTION
return result;
 }

}

Reference:  No references available.

Rule 8: Avoid_this_instanceof

Severity:  High
Rule:  Avoid this instanceof.
Reason:  Avoid this instanceof.

Usage Example: 

package com.rule;

class Avoid_this_instanceof_violation
{
public void foo()
{
if (this instanceof SubOne) // Violation
System.out.println("sub one");
}
}

class SubOne extends Avoid_this_instanceof_violation
{
//
}

Should be written as:

Instead of this, change the SubOne class to extend the foo() method.

Reference:  Reference Not Available.

Rule 9: Do_not_hide_inherited_fields

Severity:  Medium
Rule:  Avoid hiding inherited fields in child class.
Reason:  Avoid hiding inherited fields in child class.

Usage Example: 

package com.rule;

public class Do_not_hide_inherited_fields_violation implements Do_not_hide_inherited_fields_Interface_violation
{
protected int index;
public String name; // VIOLATION
private long id;
int[] values;
}

class Do_not_hide_inherited_fields_Child_violation extends Do_not_hide_inherited_fields_violation
{
private long index; // VIOLATION
protected Object name; // VIOLATION
short id; // VIOLATION
public Integer[] values;
String name2;
}

interface Do_not_hide_inherited_fields_Interface_violation
{
String name="NAME";
}

Should be written as:

Either rename the variables to use different names or remove the variables from child class and use the ones declared in parent class or interface.

Reference:  http://www.sys-con.com/story/feedback.cfm?storyid=46344

Rule 10: Override_equals_if_overriding_compareTo

Severity:  Medium
Rule:  Override equals if overriding compareTo.
Reason:  Override equals if overriding compareTo.

Usage Example: 

package com.rule;
classOverride_equals_if_overriding_compareTo_violation  implements Comparable
{
int i;
MyClas(int i)
{
this.i = i;
}

public boolean compareTo(Object o)
{
MyClass om = ...
if(i ==  om.i)
{
return 0;
}
if (i < om.i)
return -1

return 1;

}
}

Should be written as:

package com.rule;
classOverride_equals_if_overriding_compareTo_correction  implements Comparable
{
int i;
MyClas(int i)
{
this.i = i;
}

public boolean equals(Object o)// Correction
{
return i == ((MyClass) o).i
}

public boolean compareTo(Object o)
{
MyClass om = ...
if(i ==  om.i)
{
return 0;
}
if (i < om.i)
return -1

return 1;
}
}

Reference:  http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Comparable.html#compareTo(java.lang.Object)

Rule 11: Avoid_abstract_modifier_with_interface

Severity:  Low
Rule:  Avoid abstract modifier with interface.
Reason:  Avoid abstract modifier with interface.

Usage Example: 

package com.rule;
public abstract interface Avoid_abstract_modifier_with_interface_violation// Violation 
{
//...
}

Should be written as:

package com.rule;

public  interface Avoid_abstract_modifier_with_interface_correction// Correction 
{
//...
}

Reference:  http://java.sun.com/docs/books/tutorial/java/interpack/interfaceDef.html

Rule 12: Do_not_hide_inherited_static_methods

Severity:  Medium
Rule:  Avoid hiding the inherited static methods.
Reason:  Avoid hiding the inherited static methods.

Usage Example: 

package com.rule;

public class Do_not_hide_inherited_static_methods_violation
{
protected static void method()
{
}
private static void method2()
{
}
}

class Do_not_hide_inherited_static_methods_CHILD extends Do_not_hide_inherited_static_methods_violation
{
public static void method() // VIOLATION
{
}
protected static void method2()
{
}
}

Should be written as:

package com.rule;

public class Do_not_hide_inherited_static_methods_correction
{
protected static void method()
{
}
private static void method2()
{
}
}

class Do_not_hide_inherited_static_methods_CHILD extends Do_not_hide_inherited_static_methods_correction
{
public static void otherMethod() // CORRECTION
{
}
protected static void method2()
{
}
}

Reference:  Reference Not Available.

Rule 13: Always_call_super_constructor_explicitly

Severity:  Low
Rule:  Always call super-class constructor explicitly from sub-class constructor.
Reason:  Always call super-class constructor explicitly from sub-class constructor.

Usage Example: 

package com.rule;

public class Always_call_super_constructor_explicitly_violation extends Always_call_super_constructor_explicitly_super
{
public Always_call_super_constructor_explicitly_violation() // VIOLATION
{
}
}

class Always_call_super_constructor_explicitly_super
{
}

Should be written as:

package com.rule;

public class Always_call_super_constructor_explicitly_correction extends Always_call_super_constructor_explicitly_super
{
public Always_call_super_constructor_explicitly_correction() 
{
super(); // CORRECTION
}
}

class Always_call_super_constructor_explicitly_super
{
}

Reference:  http://www.bluej.org/objects-first/styleguide.html

Rule 14: Declare_only_private_constructors_in_utility_classes

Severity:  Medium
Rule:  The utility class should contain only private constructor.
Reason:  The utility class should contain only private constructor.

Usage Example: 

package com.rule;

public class Declare_only_private_constructors_in_utility_classes_violation
{
static int ID = 12345;
static String name = "Declare_only_private_constructors_in_utility_classes_violation";

static String getName()
{
return name;
}

Declare_only_private_constructors_in_utility_classes_violation() // VIOLATION
{
}

private Declare_only_private_constructors_in_utility_classes_violation(int id)
{
ID = id;
}
}

Should be written as:

package com.rule;

public class Declare_only_private_constructors_in_utility_classes_correction
{
static int ID = 12345;
static String name = "Declare_only_private_constructors_in_utility_classes_correction";

static String getName()
{
return name;
}

private Declare_only_private_constructors_in_utility_classes_correction() // CORRECTION
{
}

private Declare_only_private_constructors_in_utility_classes_correction(int id)
{
ID = id;
}
}

Reference:  http://www.devx.com/tips/Tip/14829
http://www.cs.umd.edu/class/spring2003/cmsc433/joint/EffectiveProgramming.pdf

Rule 15: Avoid_exception_as_flow_control

Severity:  High
Rule:  Avoid exception throwing as flow control.
Reason:  Avoid exception throwing as flow control.

Usage Example: 

package com.rule

class Avoid_exception_as_flow_control
{
void method()
{
try
{
while(condition1)
{
while(condition2)
{
if (condition3)
{
throw new MyException();
}
}
}
}
catch(MyException me)
{
//do nothing
}

//some other code
}
}

Should be written as:


		

Reference:  Reference Not Available

Rule 16: Do_not_expose_collection_type_fields

Severity:  High
Rule:  The private collection type fields should not be exposed.
Reason:  The private collection type fields should not be exposed.

Usage Example: 

package com.rule;

import java.util.ArrayList;

public class Do_not_expose_collection_type_fields_violation
{
private ArrayList alList = new ArrayList();

public ArrayList getList()
{
return alList; // VIOLATION
}
}

Should be written as:

package com.rule;

import java.util.ArrayList;

public class Do_not_expose_collection_type_fields_correction
{
private ArrayList alList = new ArrayList();

public Object getObject(int i) // CORRECTION
{
return alList.get(i);
}

public void addObject(int i, Object o) // CORRECTION
{
alList.add(i, o);
}

public Object removeObject(int i) // CORRECTION
{
return alList.remove(i);
}
}

Reference:  http://www.ambysoft.com/javaCodingStandards.pdf (pt 3.4.2.3)

Rule 17: Avoid_returning_internal_array

Severity:  High
Rule:  Internal arrays should not be exposed.
Reason:  Internal arrays should not be exposed.

Usage Example: 

public class AvoidReturningInternalArray
{
String[] arr;

public String[] getArr()
{
return arr; // VIOLATION
}

public String[] getThisArr()
{
return this.arr; // VIOLATION
}

public String[] getArrBad()
{
String[] arr;
return this.arr; // VIOLATION
}
}

Should be written as:

Return a copy of the array instead.

Reference:  No references available.

Rule 18: Avoid_deep_inheritance_hierarchy

Severity:  Critical
Rule:  Avoid too deep inheritance hierarchy.
Reason:  Avoid too deep inheritance hierarchy.

Usage Example: 

package com.rule;
public class Avoid_deep_inheritance_hierarchy_violation 
{
}
class inherit1 extends Avoid_deep_inheritance_hierarchy_violation
{
}
class inherit2 extends inherit1
{
}
class inherit3 extends inherit2
{
}
class inherit4 extends inherit3
{
}
class inherit5 extends inherit4
{
}
class inherit6 extends inherit5// Violation
{
}

Should be written as:

Avoid too deep inheritance hierarchy.

Reference:  http://www.javapractices.com/Topic72.cjp

Rule 19: Always_declare_instance_fields_private

Severity:  High
Rule:  Always declare all instance variables of a class private.
Reason:  Always declare all instance variables of a class private.

Usage Example: 

package com.rule;

class Always_declare_instance_fields_private_violation
{
public int i; // VIOLATION
//...
Always_declare_instance_fields_private_violation()
{
i = 1;
}
}

Should be written as:

package com.rule;

class Always_declare_instance_fields_private_correction
{
private int i; //CORRECTION
//...

Always_declare_instance_fields_private_correction()
{
i = 1;
}
}

Reference:  http://java.sun.com/docs/codeconv/html/CodeConventions.doc9.html#177

Rule 20: Do_not_override_private_methods

Severity:  Medium
Rule:  Avoid writing a method with same signature as that of a private method in parent classes.
Reason:  Avoid writing a method with same signature as that of a private method in parent classes.

Usage Example: 

package medium.oops;

public class Do_not_override_private_methods_violation
{
private void method()
{
}
}

class Do_not_override_private_methods_CHILD extends Do_not_override_private_methods_violation
{
public String method() // VIOLATION
{
return "abcde";
}
}

Should be written as:

package medium.oops;

public class Do_not_override_private_methods_correction
{
private void method()
{
}
}

class Do_not_override_private_methods_CHILD extends Do_not_override_private_methods_correction
{
public String otherMethod() // CORRECTION
{
return "abcde";
}
}

Reference:  Reference Not Available.

Rule 21: Always_declare_constructors_protected_for_abstract_class

Severity:  Low
Rule:  All constructors in an abstract class should be protected.
Reason:  All constructors in an abstract class should be protected.

Usage Example: 

package com.rule;

public abstract class Always_declare_constructors_protected_for_abstract_class_violation
{
public Always_declare_constructors_protected_for_abstract_class_violation() // VIOLATION
{
}
}

Should be written as:

package com.rule;

public abstract class Always_declare_constructors_protected_for_abstract_class_correction
{
protected Always_declare_constructors_protected_for_abstract_class_correction() // CORRECTION
{
}
}

Reference:  Reference not available.

Rule 22: Make_readResolve_writeReplace_protected_or_public

Severity:  Medium
Rule:  Declare readResolve and writeReplace method protected or public.
Reason:  Declare readResolve and writeReplace method protected or public.

Usage Example: 

package com.rule;

import java.io.ObjectStreamException;
import java.io.Serializable;

public class Make_readResolve_writeReplace_protected_violation implements Serializable
{
private Object readResolve () throws ObjectStreamException // VIOLATION
{
return null; // return the proper object here
}
  
private Object writeReplace () throws ObjectStreamException // VIOLATION
{
return null; // return the proper object here


}

Should be written as:

package com.rule;

import java.io.ObjectStreamException;
import java.io.Serializable;

public class Make_readResolve_writeReplace_protected_correction implements Serializable
{
protected Object readResolve () throws ObjectStreamException // CORRECTION
{
return null; // return the proper object here
}
  
protected Object writeReplace () throws ObjectStreamException // CORRECTION
{
return null; // return the proper object here


}

Reference:  No reference available.

Rule 23: Always_override_equals_with_same_signature

Severity:  High
Rule:  Avoid covariant version of equals.
Reason:  Avoid covariant version of equals.

Usage Example: 

package com.rule;

public class Avoid_covariant_version_of_equals_violation
{
public void foo()
{
Super s1 = new Sub();
Super s2 = new Sub();
if(s1.equals(s2))
{
//...

}
}
class Sub extends Super
{
public boolean equals(Sub sub)// Violation 
{
return this == sub;
}
}

Should be written as:

package com.rule;

public class Avoid_covariant_version_of_equals_correction
{
public void foo()
{
Super s1 = new Sub();
Super s2 = new Sub();
if(s1.equals(s2))
{
//...
}
}
}
class Sub extends Super
{
public boolean equals(java.lang.Object sub)  // Correction
{
return this == sub;
}
}

Reference:  Reference not available.

Rule 24: Avoid_suspicious_version_of_hashcode

Severity:  High
Rule:  Avoid suspicious version of Hashcode.
Reason:  Avoid suspicious version of Hashcode.

Usage Example: 

package com.rule;

public class Avoid_suspicious_version_of_hashcode
{
public int hashcode() //Violation
{
 return int;
}
public String hashCode(String s) //Violation
{
 return int;
}
public int hashcode(String s) //Violation
{
return int;
}
public int HASHCODE() //Violation
{
 return int;
}
}

Should be written as:


		

Reference:  Reference not available.

Rule 25: Provide_private_default_constructor_in_utility_classes

Severity:  Medium
Rule:  The utility class should contain private default constructor.
Reason:  The utility class should contain private default constructor.

Usage Example: 

package com.rule;

public class Provide_private_default_constructor_in_utility_classes_violation // VIOLATION
{
static int ID = 12345;
static String name = "Provide_private_default_constructor_in_utility_classes_violation";

static String getName()
{
return name;
}
}

Should be written as:

package com.rule;

public class Provide_private_default_constructor_in_utility_classes_correction
{
static int ID = 12345;
static String name = "Provide_private_default_constructor_in_utility_classes_correction";

static String getName()
{
return name;
}

private Provide_private_default_constructor_in_utility_classes_correction() // CORRECTION
{
}
}

Reference:  http://www.devx.com/tips/Tip/14829
http://www.cs.umd.edu/class/spring2003/cmsc433/joint/EffectiveProgramming.pdf

Rule 26: Avoid_redundant_finalizers

Severity:  Medium
Rule:  If a finalize method does nothing besides call super.finalize, it is redundant and can be removed.
Reason:  If a finalize method does nothing besides call super.finalize, it is redundant and can be removed.

Usage Example: 

public class Test
{
 protected void finalize() throws Throwable  // VIOLATION
 {
  super.finalize();
 }
}

Should be written as:

public class Test
{
 // FIXED
}

Reference:  Not Available.

Rule 27: Avoid_synchronize_on_lock_implementation

Severity:  Low
Rule:  Avoid synchronize on Lock implementation.
Reason:  Avoid synchronize on Lock implementation.

Usage Example: 

package com.rule;
import java.util.concurrent.locks.Lock;

public class Avoid_synchronize_on_lock_implementation_violation implements Lock
{
public void foo()
{
synchronized(this) violation
{
//...
}
}

}

Should be written as:

package com.rule;
import java.util.concurrent.locks.Lock;

public class Avoid_synchronize_on_lock_implementation_correction implements Lock
{
public void foo()
{
this.lock(); // Correction
try
{
//...
}
catch() {}
finally
{
this.unlock();
}

}

}

Reference:  http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/locks/Lock.html

Rule 28: Avoid_misleading_class_name

Severity:  Low
Rule:  Class does not extends java.lang.Exception, but class name has the word Exceptiopn at the end.
Reason:  Class does not extends java.lang.Exception, but class name has the word Exceptiopn at the end.

Usage Example: 

public class Avoid_naming_class_as_Exception // VIOLATION
{
// ....
}

Should be written as:


		

Reference:  http://www.hacknot.info/hacknot/action/showEntry?eid=48

Rule 29: Use_interface_references_to_collection

Severity:  Low
Rule:  Use interface references to collection.
Reason:  Use interface references to collection.

Usage Example: 

package com.rule;
import java.util.HashMap;

public class Use_interface_reference_to_collection_violation
{
  public void foo()
{
HashMap hm = new HashMap();// Violation
//...
}
}

Should be written as:

package com.rule;
import java.util.Map;
import java.util.HashMap;

public class Use_interface_reference_to_collection_correction
{
   public void foo()
{
Map hm = new HashMap();// Correction
}
}

Reference:  http://www . javapractices.com/Topic26.cjp

Rule 30: Avoid_instanceof_checks_in_catch_clause

Severity:  High
Rule:  Avoid Instanceof Checks In Catch Clause.
Reason:  Avoid Instanceof Checks In Catch Clause.

Usage Example: 

package com.rule;

public class Avoid_Instanceof_Checks_In_Catch_Clause
{
try
{
// Some Code...
}
catch (Exception e)
{
if (e instanceof IOException) // Violation
{
//Handle IOException
}
else if (e instanceof NumberFormatException) // Violation
{
//Handle NumberFormatException
}
}
}

Should be written as:

package com.rule;

public class Avoid_Instanceof_Checks_In_Catch_Clause
{
try
{
// Some Code...
}
catch (IOException e)
{
//Handle IOException
}
catch (NumberFormatException e)
{
//Handle NumberFormatException
}
}

Reference:  Reference not available.

Rule 31: Avoid_nested_inner_classes

Severity:  Medium
Rule:  Do not create deeper nesting of inner / anonymous classes.
Reason:  Do not create deeper nesting of inner / anonymous classes.

Usage Example: 

package com.rule;

public class Avoid_nested_inner_classes_violation
{
static class Avoid_nested_inner_classes_INNER1
{
class Avoid_nested_inner_classes_INNER2
{
class Avoid_nested_inner_classes_INNER3 // VIOLATION
{
class Avoid_nested_inner_classes_INNER4 // VIOLATION
{
class Avoid_nested_inner_classes_INNER5 // VIOLATION
{
}
}
}
}
}
}

Should be written as:

Remove the inner classes and make them seperate classes.

Reference:  Reference Not Available.

Rule 32: Avoid_empty_body_for_implemented_methods

Severity:  Medium
Rule:  If a class implements an interface it should provide non-empty implementation of all the methods.
Reason:  If a class implements an interface it should provide non-empty implementation of all the methods.

Usage Example: 

package com.rule;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Avoid_empty_body_for_implemented_methods_violation implements ActionListener
{

public void actionPerformed(ActionEvent e) // VIOLATION
{
}

}

Should be written as:

package com.rule;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public abstract class Avoid_empty_body_for_implemented_methods_correction implements ActionListener
{

public abstract void actionPerformed(ActionEvent e); // CORRECTION

}

Reference:  No reference available.

Rule 33: Avoid_abstract_class_without_abstract_method

Severity:  Medium
Rule:  A class without any abstract method should not be declared abstract
Reason:  A class without any abstract method should not be declared abstract

Usage Example: 

package com.rule;

abstract class Avoid_abstract_class_without_abstract_method_violation // VIOLATION
{
void method
{
//...
}
}

Should be written as:

package com.rule;

abstract class Avoid_abstract_class_without_abstract_method_violation
{
abstract void method(); // CORRECTION
}

Reference:  Reference Not Available.

Rule 34: Do_not_override_nonabstract_methods_with_abstract_methods

Severity:  Low
Rule:  A non-abstract method should not be overriden with abstract methods.
Reason:  A non-abstract method should not be overriden with abstract methods.

Usage Example: 

package com.rule;

public class Do_not_override_nonabstract_methods_with_abstract_methods
{
public void method()
{
}
}

abstract class Do_not_override_nonabstract_methods_with_abstract_methods_CHILD
extends Do_not_override_nonabstract_methods_with_abstract_methods
{
public abstract void method(); // VIOLATION
}

Should be written as:

Never override a non-abstract method with an abstract method. Instead you can use some other name for the abstract method.

Reference:  No reference available.

https://igamingseopro.com/
We use cookies for analytics, advertising and to improve our site. By continuing to use our site, you accept to our Privacy policy and allow us to store cookies.