- 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);
- 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.
solution:
# Date类型为例:
public void setHappenTime(Date happenTime) {
if(happenTime != null){
this.happenTime = (Date) happenTime.clone();
}else{
this.happenTime = null;
}
}
# 数组
public String[] setStringArrary(String[] arr) {
if(arr != null){
this.stringArrays = Arrays.copyOf(stringArray, stringArray.length);
} else {
this.stringArrays =null;
}
}
3.CN_IDIOM_NO_SUPER_CALL
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.
- findbugs:DC_DOUBLECHECK
multi-threading – Possible double check of field
multi-threading double check of field
, solution, add volatile keyword decoration to the field.
- [NP_NULL_PARAM_DEREF]
description: Null passed for nonnull parameter passed to nonnull parameter
solution: add nonnull judgment
Read More:
- SqlNullValueException: Data is Null. This method or property cannot be called on Null values.
- 1、 Java 8 date and local date
- Definition of bracket type in typescript
- Detailed explanation of Python__ new__() method
- Java retainAll throws an unsupported operation exception record
- org.apache.ibatis.type.TypeException: Error setting non null for parameter #4 with JdbcType null
- JavaScript summary: the difference between typeof and instanceof, and Object.prototype.toString() method
- [Solved] Flowable Start Error: ClassCastException: java.time.LocalDateTime cannot be cast to java.lang.String
- Pit encountered by entity class data type BigDecimal
- Research on LRU algorithm
- An unable to locate appropriate constructor on class solution appears
- Default constructor cannot handle exception type FileNotFoundException thrown by implicit super cons
- 209151; org.json.JSONException A JSONObject text must begin with'{‘at character 1 of {
- “Invalid month” in SQL query
- Domain error in object XXX “other” domain “other” rejected values and atm913
- Java gets the type t.class of generic t
- Error analysis of queryformap method of jdbctemplate
- Error type referred to is not an annotation type:RedisCache
- About OSS file download and rename
- java.util.Collections.max() [How to Use]