Details about the known misuse from the MUBench dataset.
Description: | UnionTypeBuilder.build() returns a JSType that can never be null. Branching on a null check therefore results in dead code.
|
Fix Description: |
Check Node.isNoType() instead.
(see diff) |
Violation Types: |
- superfluous/condition/null_check
|
In File: | com/google/javascript/rhino/jstype/UnionType.java |
In Method: | meet(JSType) |
Code with Misuse: |
class UnionType {
JSType meet(JSType that) {
UnionTypeBuilder builder = new UnionTypeBuilder(registry);
for (JSType alternate : alternates) {
if (alternate.isSubtype(that)) {
builder.addAlternate(alternate);
}
}
if (that instanceof UnionType) {
for (JSType otherAlternate : ((UnionType) that).alternates) {
if (otherAlternate.isSubtype(this)) {
builder.addAlternate(otherAlternate);
}
}
} else if (that.isSubtype(this)) {
builder.addAlternate(that);
}
JSType result = builder.build();
if (result != null) {
return result;
} else if (this.isObject() && that.isObject()) {
return getNativeType(JSTypeNative.NO_OBJECT_TYPE);
} else {
return getNativeType(JSTypeNative.NO_TYPE);
}
}
}
|
Code with Pattern(s): |
public class IsNotType {
public JSType pattern(UnionTypeBuilder builder) {
JSType result = builder.build();
if(!result.isNoType()) {
return result;
} else {
return null; // default value
}
}
}
|