- 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:
- Common attributes and methods of list and map in Dar
- Several common methods of inserting pictures into latex documents
- Common errors and solutions in MapReduce stage
- R-common errors and their possible causes — Notes
- Analysis and solution of common errors in ArcEngine development
- Common errors and solutions of Qt development application under Ubuntu
- Summary of common errors in angularjs
- How to Solve Yolov5 Common Error (Three Errors)
- C + + common errors: “error: XXX in namespace ‘STD’ does not name a template type”
- Methods to avoid fail to allocate bitmap errors in pyplot
- Common errors in k8s initialization_ [WARNING NumCPU]_ [WARNING SystemVerification]_ WARNING Hostname
- Common errors reported by Eureka in spring cloud
- Common solutions to errors in checkout or commit of SVN
- Kafka connection abnormal org.apache.kafka . common.errors.TimeoutException : Failed to update metadata after 60000 ms.
- SQL Union, union all usage and common errors and Solutions
- Error: php56w-common conflicts with php-common-5.3.3-48.el6_ 8.x86_ 64
- Python windows error: [error 3] and common windows error errors
- New fields in hive table and modification of field comments
- Modification method of starting value of MySQL auto increment ID