Skip to content

Commit 9624eb7

Browse files
committed
add bugtype UVA_REMOVE_NULL_ARG
1 parent 75f2bb1 commit 9624eb7

File tree

7 files changed

+241
-169
lines changed

7 files changed

+241
-169
lines changed

etc/bugrank.txt

+1
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@
307307
+3 BugPattern UTAO_TESTNG_ASSERTION_ODDITIES_USE_ASSERT_NULL
308308
+0 BugPattern UTA_USE_TO_ARRAY
309309
+0 BugPattern UTWR_USE_TRY_WITH_RESOURCES
310+
+0 BugPattern UVA_REMOVE_NULL_ARG
310311
+0 BugPattern UVA_USE_VAR_ARGS
311312
+0 BugPattern WEM_OBSCURING_EXCEPTION
312313
+0 BugPattern WEM_WEAK_EXCEPTION_MESSAGING

etc/findbugs.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@
218218

219219
<Detector class="com.mebigfatguy.fbcontrib.detect.WriteOnlyCollection" speed="fast" reports="WOC_WRITE_ONLY_COLLECTION_LOCAL,WOC_WRITE_ONLY_COLLECTION_FIELD" />
220220

221-
<Detector class="com.mebigfatguy.fbcontrib.detect.UseVarArgs" speed="fast" reports="UVA_USE_VAR_ARGS" />
221+
<Detector class="com.mebigfatguy.fbcontrib.detect.UseVarArgs" speed="fast" reports="UVA_USE_VAR_ARGS,UVA_REMOVE_NULL_ARG" />
222222

223223
<Detector class="com.mebigfatguy.fbcontrib.detect.PossibleUnsuspectedSerialization" speed="fast" reports="PUS_POSSIBLE_UNSUSPECTED_SERIALIZATION" />
224224

@@ -545,6 +545,7 @@
545545
<BugPattern abbrev="WOC" type="WOC_WRITE_ONLY_COLLECTION_LOCAL" category="CORRECTNESS" />
546546
<BugPattern abbrev="WOC" type="WOC_WRITE_ONLY_COLLECTION_FIELD" category="CORRECTNESS" />
547547
<BugPattern abbrev="UVA" type="UVA_USE_VAR_ARGS" category="STYLE" />
548+
<BugPattern abbrev="UVA" type="UVA_REMOVE_NULL_ARG" category="STYLE" />
548549
<BugPattern abbrev="PUS" type="PUS_POSSIBLE_UNSUSPECTED_SERIALIZATION" category="CORRECTNESS" />
549550
<BugPattern abbrev="SEC" type="SEC_SIDE_EFFECT_CONSTRUCTOR" category="STYLE" />
550551
<BugPattern abbrev="SGSU" type="SGSU_SUSPICIOUS_GETTER_SETTER_USE" category="CORRECTNESS" />

etc/messages.xml

+13-1
Original file line numberDiff line numberDiff line change
@@ -4840,7 +4840,19 @@ if (name != null) {
48404840
]]>
48414841
</Details>
48424842
</BugPattern>
4843-
4843+
4844+
<BugPattern type="UVA_REMOVE_NULL_ARG">
4845+
<ShortDescription>Method passes explicit null value to var arg parameter</ShortDescription>
4846+
<LongDescription>Method {1} passes explicit null value to var arg parameter</LongDescription>
4847+
<Details>
4848+
<![CDATA[
4849+
<p>This method calls a var arg method, and passes an explicit null value as the var arg parameter.
4850+
It is better to just not pass any value at all, as there is confusion as to whether the null represents
4851+
the entire vararg array, or the first element of the varargs array</p>
4852+
]]>
4853+
</Details>
4854+
</BugPattern>
4855+
48444856
<BugPattern type="PUS_POSSIBLE_UNSUSPECTED_SERIALIZATION">
48454857
<ShortDescription>Method serializes an instance of a non-static inner class</ShortDescription>
48464858
<LongDescription>Method {1} serializes an instance of a non-static inner class</LongDescription>

src/main/java/com/mebigfatguy/fbcontrib/collect/MethodInfo.java

+129-125
Original file line numberDiff line numberDiff line change
@@ -27,129 +27,133 @@
2727
*/
2828
public class MethodInfo {
2929

30-
public static final int PUBLIC_USE = 1;
31-
public static final int PRIVATE_USE = 2;
32-
public static final int PROTECTED_USE = 4;
33-
public static final int PACKAGE_USE = 8;
34-
35-
private short numMethodBytes;
36-
private byte numMethodCalls;
37-
private byte immutabilityOrdinal;
38-
private byte declaredAccess;
39-
private byte isCalledType;
40-
private boolean modifiesState;
41-
private boolean canReturnNull;
42-
private boolean isDerived;
43-
44-
public int getNumBytes() {
45-
return 0x0000FFFF & numMethodBytes;
46-
}
47-
48-
public void setNumBytes(int numBytes) {
49-
numMethodBytes = (short) numBytes;
50-
}
51-
52-
public int getNumMethodCalls() {
53-
return 0x000000FF & numMethodCalls;
54-
}
55-
56-
public void setNumMethodCalls(int numCalls) {
57-
numMethodCalls = numCalls > 255 ? Byte.MAX_VALUE : (byte) numCalls;
58-
}
59-
60-
public void setDeclaredAccess(int access) {
61-
declaredAccess = (byte) access;
62-
}
63-
64-
public int getDeclaredAccess() {
65-
return declaredAccess;
66-
}
67-
68-
public void addCallingAccess(int access) {
69-
if ((access & Const.ACC_PUBLIC) != 0) {
70-
isCalledType |= PUBLIC_USE;
71-
} else if ((access & Const.ACC_PROTECTED) != 0) {
72-
isCalledType |= PROTECTED_USE;
73-
} else if ((access & Const.ACC_PRIVATE) != 0) {
74-
isCalledType |= PRIVATE_USE;
75-
} else {
76-
isCalledType |= PACKAGE_USE;
77-
}
78-
}
79-
80-
public boolean wasCalled() {
81-
return (isCalledType & (PUBLIC_USE | PROTECTED_USE | PACKAGE_USE | PRIVATE_USE)) != 0;
82-
}
83-
84-
public boolean wasCalledPublicly() {
85-
return (isCalledType & PUBLIC_USE) != 0;
86-
}
87-
88-
public boolean wasCalledProtectedly() {
89-
return (isCalledType & PROTECTED_USE) != 0;
90-
}
91-
92-
public boolean wasCalledPackagely() {
93-
return (isCalledType & PACKAGE_USE) != 0;
94-
}
95-
96-
public boolean wasCalledPrivately() {
97-
return (isCalledType & PRIVATE_USE) != 0;
98-
}
99-
100-
public ImmutabilityType getImmutabilityType() {
101-
return ImmutabilityType.values()[immutabilityOrdinal];
102-
}
103-
104-
public void setImmutabilityType(ImmutabilityType imType) {
105-
immutabilityOrdinal = (byte) imType.ordinal();
106-
}
107-
108-
public boolean getModifiesState() {
109-
return modifiesState;
110-
}
111-
112-
public void setModifiesState(boolean modifiesState) {
113-
this.modifiesState = modifiesState;
114-
}
115-
116-
public boolean getCanReturnNull() {
117-
return canReturnNull;
118-
}
119-
120-
public void setCanReturnNull(boolean canReturnNull) {
121-
this.canReturnNull = canReturnNull;
122-
}
123-
124-
public boolean isDerived() {
125-
return isDerived;
126-
}
127-
128-
public void setDerived(boolean isDerived) {
129-
this.isDerived = isDerived;
130-
}
131-
132-
@Override
133-
public boolean equals(Object o) {
134-
if (!(o instanceof MethodInfo)) {
135-
return false;
136-
}
137-
138-
MethodInfo mi = (MethodInfo) o;
139-
140-
return (numMethodBytes == mi.numMethodBytes) && (numMethodCalls == mi.numMethodCalls)
141-
&& (immutabilityOrdinal == mi.immutabilityOrdinal) && (declaredAccess == mi.declaredAccess)
142-
&& (isCalledType == mi.isCalledType) && (modifiesState == mi.modifiesState);
143-
}
144-
145-
@Override
146-
public int hashCode() {
147-
return numMethodBytes ^ numMethodCalls ^ immutabilityOrdinal ^ declaredAccess ^ isCalledType
148-
^ (modifiesState ? 1 : -1);
149-
}
150-
151-
@Override
152-
public String toString() {
153-
return ToString.build(this);
154-
}
30+
public static final int PUBLIC_USE = 1;
31+
public static final int PRIVATE_USE = 2;
32+
public static final int PROTECTED_USE = 4;
33+
public static final int PACKAGE_USE = 8;
34+
35+
private short numMethodBytes;
36+
private byte numMethodCalls;
37+
private byte immutabilityOrdinal;
38+
private byte declaredAccess;
39+
private byte isCalledType;
40+
private boolean modifiesState;
41+
private boolean canReturnNull;
42+
private boolean isDerived;
43+
44+
public int getNumBytes() {
45+
return 0x0000FFFF & numMethodBytes;
46+
}
47+
48+
public void setNumBytes(int numBytes) {
49+
numMethodBytes = (short) numBytes;
50+
}
51+
52+
public int getNumMethodCalls() {
53+
return 0x000000FF & numMethodCalls;
54+
}
55+
56+
public void setNumMethodCalls(int numCalls) {
57+
numMethodCalls = numCalls > 255 ? Byte.MAX_VALUE : (byte) numCalls;
58+
}
59+
60+
public void setDeclaredAccess(int access) {
61+
declaredAccess = (byte) access;
62+
}
63+
64+
public int getDeclaredAccess() {
65+
return declaredAccess;
66+
}
67+
68+
public void addCallingAccess(int access) {
69+
if ((access & Const.ACC_PUBLIC) != 0) {
70+
isCalledType |= PUBLIC_USE;
71+
} else if ((access & Const.ACC_PROTECTED) != 0) {
72+
isCalledType |= PROTECTED_USE;
73+
} else if ((access & Const.ACC_PRIVATE) != 0) {
74+
isCalledType |= PRIVATE_USE;
75+
} else {
76+
isCalledType |= PACKAGE_USE;
77+
}
78+
}
79+
80+
public boolean wasCalled() {
81+
return (isCalledType & (PUBLIC_USE | PROTECTED_USE | PACKAGE_USE | PRIVATE_USE)) != 0;
82+
}
83+
84+
public boolean wasCalledPublicly() {
85+
return (isCalledType & PUBLIC_USE) != 0;
86+
}
87+
88+
public boolean wasCalledProtectedly() {
89+
return (isCalledType & PROTECTED_USE) != 0;
90+
}
91+
92+
public boolean wasCalledPackagely() {
93+
return (isCalledType & PACKAGE_USE) != 0;
94+
}
95+
96+
public boolean wasCalledPrivately() {
97+
return (isCalledType & PRIVATE_USE) != 0;
98+
}
99+
100+
public ImmutabilityType getImmutabilityType() {
101+
return ImmutabilityType.values()[immutabilityOrdinal];
102+
}
103+
104+
public void setImmutabilityType(ImmutabilityType imType) {
105+
immutabilityOrdinal = (byte) imType.ordinal();
106+
}
107+
108+
public boolean getModifiesState() {
109+
return modifiesState;
110+
}
111+
112+
public void setModifiesState(boolean modifiesState) {
113+
this.modifiesState = modifiesState;
114+
}
115+
116+
public boolean getCanReturnNull() {
117+
return canReturnNull;
118+
}
119+
120+
public void setCanReturnNull(boolean canReturnNull) {
121+
this.canReturnNull = canReturnNull;
122+
}
123+
124+
public boolean isDerived() {
125+
return isDerived;
126+
}
127+
128+
public void setDerived(boolean isDerived) {
129+
this.isDerived = isDerived;
130+
}
131+
132+
public boolean isVarArg() {
133+
return (declaredAccess & Const.ACC_VARARGS) != 0;
134+
}
135+
136+
@Override
137+
public boolean equals(Object o) {
138+
if (!(o instanceof MethodInfo)) {
139+
return false;
140+
}
141+
142+
MethodInfo mi = (MethodInfo) o;
143+
144+
return (numMethodBytes == mi.numMethodBytes) && (numMethodCalls == mi.numMethodCalls)
145+
&& (immutabilityOrdinal == mi.immutabilityOrdinal) && (declaredAccess == mi.declaredAccess)
146+
&& (isCalledType == mi.isCalledType) && (modifiesState == mi.modifiesState);
147+
}
148+
149+
@Override
150+
public int hashCode() {
151+
return numMethodBytes ^ numMethodCalls ^ immutabilityOrdinal ^ declaredAccess ^ isCalledType
152+
^ (modifiesState ? 1 : -1);
153+
}
154+
155+
@Override
156+
public String toString() {
157+
return ToString.build(this);
158+
}
155159
}

0 commit comments

Comments
 (0)