Common errors and modification methods of findbug

  1. findbugs:EI_EXPOSE_REP
    problem description: Getters and setters of the may expose internal representation by returning reference type
    eclipse automatically generates reference type (Object, array, Date, etc.) will get or expose the inner implementation of the code by referring to the mutable Object. There are many solutions provided that the returned or assigned Object is not the original reference Object.
# Date
public Date getHappenTime() {
if(happenTime != null){
return (Date) happenTime.clone();
    return null;
# 数组
public String[] getStringArrary() {
if(stringArray != null){
return Arrays.copyOf(stringArray, stringArray.length);
    return null;
# hashTable
table = new HashTable(hashTable);
  1. findbugs: EI_EXPOSE_REP2
    description: May expose internal representation by storing the an externally mutable object into a setter method returns a reference type
    eclipse to automatically generate a reference type (object, array, the Date, etc.) or through the getter and setter methods get the variable object reference operation and internal implementation code, open the solution a lot, As long as the returned or assigned object is not the original reference object.
# Date类型为例:
public void setHappenTime(Date happenTime) {
if(happenTime != null){
this.happenTime = (Date) happenTime.clone();
this.happenTime = null;
# 数组
public String[] setStringArrary(String[] arr) {
if(arr != null){
this.stringArrays = Arrays.copyOf(stringArray, stringArray.length);
} else {
 this.stringArrays =null;


clone method does not call super.clone()
a non-final class defined the clone() method without calling the super.clone() method. For example: B extends from A and if the clone method in B calls spuer.clone() and the clone in A does not call spuer.clone(), that results in an inaccurate result type. Spuer. clone() is called from A’s clone method.

  1. findbugs:DC_DOUBLECHECK

multi-threading – Possible double check of field
multi-threading double check of field
, solution, add volatile keyword decoration to the field.

    description: Null passed for nonnull parameter passed to nonnull parameter
    solution: add nonnull judgment

Read More: