Examples of errors detected by the V6032 diagnostic
V6032. It is odd that the body of 'Foo_1' function is fully equivalent to the body of 'Foo_2' function.
SonarQube
V6032 It is odd that the body of method 'setUpdatedAtFromDefinition' is fully equivalent to the body of another method 'setUpdatedAtFromMetadata'. Check lines: 396, 405. RuleDto.java 396
public class RuleDto {
....
private final RuleDefinitionDto definition;
private final RuleMetadataDto metadata;
....
private void setUpdatedAtFromDefinition(@Nullable Long updatedAt) {
if (updatedAt != null && updatedAt > definition.getUpdatedAt()) {
setUpdatedAt(updatedAt);
}
}
private void setUpdatedAtFromMetadata(@Nullable Long updatedAt) {
if (updatedAt != null && updatedAt > definition.getUpdatedAt()) {
setUpdatedAt(updatedAt);
}
}
....
}
A definition field is used in the method setUpdatedAtFromMetadata. Most likely, the metadata field should be used. This is very similar to the effects of a failed Copy-Paste.
CUBA Platform
V6032 It is odd that the body of method 'firstItemId' is fully equivalent to the body of another method 'lastItemId'. ContainerTableItems.java(213), ContainerTableItems.java(219)
@Override
public Object firstItemId() {
List<E> items = container.getItems();
return items.isEmpty() ? null : items.get(0).getId();
}
@Override
public Object lastItemId() {
List<E> items = container.getItems();
return items.isEmpty() ? null : items.get(0).getId();
}
CUBA Platform
V6032 It is odd that the body of method is fully equivalent to the body of another method. SearchComboBoxPainter.java(495), SearchComboBoxPainter.java(501)
private void paintBackgroundDisabledAndEditable(Graphics2D g) {
rect = decodeRect1();
g.setPaint(color53);
g.fill(rect);
}
private void paintBackgroundEnabledAndEditable(Graphics2D g) {
rect = decodeRect1();
g.setPaint(color53);
g.fill(rect);
}
Huawei Cloud
V6032 It is odd that the body of method 'enable' is fully equivalent to the body of another method 'disable'. ServiceAction.java(32), ServiceAction.java(36)
public class ServiceAction implements ModelEntity
{
private String binary;
private String host;
private ServiceAction(String binary, String host) {
this.binary = binary;
this.host = host;
}
public static ServiceAction enable(String binary, String host) { // <=
return new ServiceAction(binary, host);
}
public static ServiceAction disable(String binary, String host) { // <=
return new ServiceAction(binary, host);
}
....
}
Apache Flink
V6032 It is odd that the body of method 'seekToFirst' is fully equivalent to the body of another method 'seekToLast'. RocksIteratorWrapper.java(53), RocksIteratorWrapper.java(59)
public class RocksIteratorWrapper implements RocksIteratorInterface, Closeable {
....
private RocksIterator iterator;
....
@Override
public void seekToFirst() {
iterator.seekToFirst(); // <=
status();
}
@Override
public void seekToLast() {
iterator.seekToFirst(); // <=
status();
}
....
}
public class RocksIterator extends AbstractRocksIterator<RocksDB>
{
....
}
public abstract class AbstractRocksIterator<...> extends ...
{
....
public void seekToFirst() // <=
{
assert this.isOwningHandle();
this.seekToFirst0(this.nativeHandle_);
}
public void seekToLast() // <=
{
assert this.isOwningHandle();
this.seekToLast0(this.nativeHandle_);
}
....
}
Rhino
V6032 It is odd that the body of method 'endCheckSwitch' is fully equivalent to the body of another method 'endCheckTry'. Node.java(681), Node.java(717)
public class Node implements Iterable<Node> {
....
private int endCheckSwitch() {
int rv = END_UNREACHED;
// examine the cases
// for (n = first.next; n != null; n = n.next)
// {
// if (n.type == Token.CASE) {
// rv |= ((Jump)n).target.endCheck();
// } else
// break;
// }
// // we don't care how the cases drop into each other
// rv &= ~END_DROPS_OFF;
// // examine the default
// n = ((Jump)this).getDefault();
// if (n != null)
// rv |= n.endCheck();
// else
// rv |= END_DROPS_OFF;
// // remove the switch block
// rv |= getIntProp(CONTROL_BLOCK_PROP, END_UNREACHED);
return rv;
}
....
private int endCheckTry() {
int rv = END_UNREACHED;
// a TryStatement isn't a jump - needs rewriting
// check the finally if it exists
// n = ((Jump)this).getFinally();
// if(n != null) {
// rv = n.next.first.endCheck();
// } else {
// rv = END_DROPS_OFF;
// }
// // if the finally block always returns, then none of the returns
// // in the try or catch blocks matter
// if ((rv & END_DROPS_OFF) != 0) {
// rv &= ~END_DROPS_OFF;
// // examine the try block
// rv |= first.endCheck();
// // check each catch block
// n = ((Jump)this).target;
// if (n != null)
// {
// // point to the first catch_scope
// for (n = n.next.first; n != null; n = n.next.next)
// {
// // check the block of user code in the catch_scope
// rv |= n.next.first.next.first.endCheck();
// }
// }
// }
return rv;
}
}
NetBeans 21
V6032 It is odd that the body of method 'addPropertyChangeListener' is fully equivalent to the body of another method 'removePropertyChangeListener'. EditorMimeTypesImpl.java(63), EditorMimeTypesImpl.java(69)
public final class EditorMimeTypesImpl
implements EditorMimeTypesImplementation {
private final PropertyChangeSupport listeners;
@Override
public void addPropertyChangeListener(@NonNull final
PropertyChangeListener listener) {
Parameters.notNull("listener", listener); //NOI18N
listeners.addPropertyChangeListener(listener);
}
@Override
public void removePropertyChangeListener(@NonNull final
PropertyChangeListener listener) {
Parameters.notNull("listener", listener); //NOI18N
listeners.addPropertyChangeListener(listener);
}
}
NetBeans 21
V6032 It is odd that the body of method 'getWidth' is fully equivalent to the body of another method 'getHeight'. MethodParamsTipPaintComponent.java(121), MethodParamsTipPaintComponent.java(126)
public class MethodParamsTipPaintComponent extends JToolTip {
protected int getWidth(String s, Font font) {
if (font == null) return fontMetrics.stringWidth(s);
return getFontMetrics(font).stringWidth(s);
}
protected int getHeight(String s, Font font) {
if (font == null) return fontMetrics.stringWidth(s);
return getFontMetrics(font).stringWidth(s);
}
}
Apache Solr
V6032 It is odd that the body of method 'makeFeatures' is fully equivalent to the body of another method 'makeFilterFeatures'. TestLTRScoringQuery.java 66, TestLTRScoringQuery.java 79
private static List<Feature> makeFeatures(int[] featureIds) {
final List<Feature> features = new ArrayList<>();
for (final int i : featureIds) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("value", i);
final Feature f = Feature.getInstance(solrResourceLoader,
ValueFeature.class.getName(), "f" + i, params);
f.setIndex(i);
features.add(f);
}
return features;
}
private static List<Feature> makeFilterFeatures(int[] featureIds) {
final List<Feature> features = new ArrayList<>();
for (final int i : featureIds) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("value", i);
final Feature f = Feature.getInstance(solrResourceLoader,
ValueFeature.class.getName(), "f" + i, params);
f.setIndex(i);
features.add(f);
}
return features;
}