Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SONARJAVA-5232 S1192 Do not consider arguments in Throwables when checking for duplicated strings #5036

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions its/ruling/src/test/resources/commons-beanutils/java-S1192.json
Original file line number Diff line number Diff line change
@@ -1,62 +1,15 @@
{
"commons-beanutils:commons-beanutils:src/main/java/org/apache/commons/beanutils2/BasicDynaBean.java": [
122,
127
],
"commons-beanutils:commons-beanutils:src/main/java/org/apache/commons/beanutils2/BasicDynaClass.java": [
269
],
"commons-beanutils:commons-beanutils:src/main/java/org/apache/commons/beanutils2/BeanUtilsBean.java": [
420,
945
],
"commons-beanutils:commons-beanutils:src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java": [
220
],
"commons-beanutils:commons-beanutils:src/main/java/org/apache/commons/beanutils2/LazyDynaBean.java": [
235,
360,
407,
728
],
"commons-beanutils:commons-beanutils:src/main/java/org/apache/commons/beanutils2/LazyDynaClass.java": [
231
],
"commons-beanutils:commons-beanutils:src/main/java/org/apache/commons/beanutils2/LazyDynaMap.java": [
224
],
"commons-beanutils:commons-beanutils:src/main/java/org/apache/commons/beanutils2/MappedPropertyDescriptor.java": [
91
],
"commons-beanutils:commons-beanutils:src/main/java/org/apache/commons/beanutils2/MethodUtils.java": [
274
],
"commons-beanutils:commons-beanutils:src/main/java/org/apache/commons/beanutils2/PropertyUtilsBean.java": [
292,
292,
363,
420,
429,
430,
494,
532,
595,
676,
783,
1625,
1627,
1630
],
"commons-beanutils:commons-beanutils:src/main/java/org/apache/commons/beanutils2/ResultSetIterator.java": [
98
],
"commons-beanutils:commons-beanutils:src/main/java/org/apache/commons/beanutils2/WrapDynaBean.java": [
141,
145
],
"commons-beanutils:commons-beanutils:src/main/java/org/apache/commons/beanutils2/converters/NumberConverter.java": [
314,
315,
319
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
"org.eclipse.jetty:jetty-project:jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java": [
276
],
"org.eclipse.jetty:jetty-project:jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java": [
974
],
"org.eclipse.jetty:jetty-project:jetty-http/src/main/java/org/eclipse/jetty/http/MimeTypes.java": [
106
],
Expand All @@ -18,9 +15,7 @@
317
],
"org.eclipse.jetty:jetty-project:jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java": [
644,
932,
1013
932
],
"org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/CustomRequestLog.java": [
597
Expand All @@ -32,8 +27,6 @@
1002
],
"org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/HttpOutput.java": [
680,
716,
1677
],
"org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/InclusiveByteRange.java": [
Expand All @@ -52,7 +45,6 @@
198
],
"org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/ShutdownMonitor.java": [
188,
359,
360,
366
Expand All @@ -63,30 +55,16 @@
"org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/handler/StatisticsHandler.java": [
575
],
"org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCache.java": [
444
],
"org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionDataStore.java": [
161
],
"org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/session/DatabaseAdaptor.java": [
107,
109
],
"org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionDataStore.java": [
277,
324,
326,
346,
352,
353,
353,
355
],
"org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/session/Session.java": [
332
],
"org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java": [
1410
]
}
41 changes: 3 additions & 38 deletions its/ruling/src/test/resources/eclipse-jetty/java-S1192.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
"org.eclipse.jetty:jetty-project:jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java": [
276
],
"org.eclipse.jetty:jetty-project:jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java": [
974
],
"org.eclipse.jetty:jetty-project:jetty-http/src/main/java/org/eclipse/jetty/http/MimeTypes.java": [
106
],
Expand All @@ -18,9 +15,7 @@
317
],
"org.eclipse.jetty:jetty-project:jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java": [
644,
932,
1013
932
],
"org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/CustomRequestLog.java": [
597
Expand All @@ -32,8 +27,6 @@
1002
],
"org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/HttpOutput.java": [
680,
716,
1677
],
"org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/InclusiveByteRange.java": [
Expand All @@ -52,7 +45,6 @@
198
],
"org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/ShutdownMonitor.java": [
188,
359,
360,
366
Expand All @@ -63,52 +55,31 @@
"org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/handler/StatisticsHandler.java": [
575
],
"org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCache.java": [
444
],
"org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionDataStore.java": [
161
],
"org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/session/DatabaseAdaptor.java": [
107,
109
],
"org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionDataStore.java": [
277,
324,
326,
346,
352,
353,
353,
355
],
"org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/session/Session.java": [
332
],
"org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java": [
1410
],
"org.eclipse.jetty:jetty-project:jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/JettyLoggerConfiguration.java": [
241,
242
],
"org.eclipse.jetty:jetty-project:jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/AsyncJSON.java": [
386,
557,
605,
648,
992
],
"org.eclipse.jetty:jetty-project:jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSON.java": [
1219
],
"org.eclipse.jetty:jetty-project:jetty-util/src/main/java/org/eclipse/jetty/util/IO.java": [
93
],
"org.eclipse.jetty:jetty-project:jetty-util/src/main/java/org/eclipse/jetty/util/IntrospectionUtil.java": [
55
],
"org.eclipse.jetty:jetty-project:jetty-util/src/main/java/org/eclipse/jetty/util/IteratingCallback.java": [
289
],
Expand All @@ -124,8 +95,7 @@
51
],
"org.eclipse.jetty:jetty-project:jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java": [
154,
444
154
],
"org.eclipse.jetty:jetty-project:jetty-util/src/main/java/org/eclipse/jetty/util/URIUtil.java": [
1163
Expand All @@ -139,9 +109,6 @@
"org.eclipse.jetty:jetty-project:jetty-util/src/main/java/org/eclipse/jetty/util/resource/URLResource.java": [
76
],
"org.eclipse.jetty:jetty-project:jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslContextFactory.java": [
1047
],
"org.eclipse.jetty:jetty-project:jetty-util/src/main/java/org/eclipse/jetty/util/thread/ReservedThreadExecutor.java": [
251
],
Expand All @@ -151,8 +118,6 @@
1033,
1074,
1129,
1129,
1535,
1535
1129
]
}
16 changes: 0 additions & 16 deletions its/ruling/src/test/resources/guava/java-S1192.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,14 @@
"com.google.guava:guava:src/com/google/common/collect/ConcurrentHashMultiset.java": [
223
],
"com.google.guava:guava:src/com/google/common/collect/Cut.java": [
141
],
"com.google.guava:guava:src/com/google/common/collect/FilteredKeyMultimap.java": [
121
],
"com.google.guava:guava:src/com/google/common/collect/MultimapBuilder.java": [
198
],
"com.google.guava:guava:src/com/google/common/io/BaseEncoding.java": [
655
],
"com.google.guava:guava:src/com/google/common/io/ByteSource.java": [
476,
477
],
"com.google.guava:guava:src/com/google/common/math/DoubleMath.java": [
398
],
"com.google.guava:guava:src/com/google/common/math/MathPreconditions.java": [
32,
53
],
"com.google.guava:guava:src/com/google/common/util/concurrent/MoreExecutors.java": [
781
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,82 @@ class Coverage {
private final String prevLeftNull = "SELECT" + 3;
private final String prevRightNull = 3 + "SELECT";
}

class DuplicatedExceptionArguments {
private void areCompliantByDefault(int r) {
if (r == 0) {
throw new IllegalArgumentException("simple IAE");
} else if (r == 1) {
throw new IllegalArgumentException("simple IAE");
} else if (r == 2) {
throw new IllegalArgumentException("simple IAE");
}
}

static class MyException extends Exception {
public MyException(String message, Throwable throwable) {
super(message, throwable);
}
}

private void twoArgs(int r, Throwable throwable) throws MyException {
if (r == 0) {
throw new MyException("my exception message", throwable);
} else if (r == 1) {
throw new MyException("my exception message", throwable);
} else if (r == 2) {
throw new MyException("my exception message", throwable);
}
}

private Throwable buildButDoNotThrow(int r) {
if (r == 0) {
return new NullPointerException("build message"); // Noncompliant {{Define a constant instead of duplicating this literal "build message" 3 times.}}
} else if (r == 1) {
return new IllegalArgumentException("build message");
} else {
return new AssertionError("build message");
}
}

private void nestedString1(int r) {
if (r == 0) {
throw new IllegalArgumentException("nested string 1".toLowerCase());
} else if (r == 1) {
throw new IllegalArgumentException("nested string 1".toUpperCase());
} else if (r == 2) {
throw new IllegalArgumentException("nested string 1");
}
}

private String transform(String s, String suffix) {
return s + suffix;
}

// This case could be revisited if it does not complicate the implementation.
private void areNonCompliantWhenPassedToMethod(int r) {
if (r == 0) {
throw new IllegalArgumentException(transform("nested string 2", "AAA")); // Noncompliant {{Define a constant instead of duplicating this literal "nested string 2" 3 times.}}
} else if (r == 1) {
throw new IllegalArgumentException(transform("nested string 2", "BBB"));
} else if (r == 2) {
throw new IllegalArgumentException(transform("nested string 2", "CCC"));
}
}

private void concatenationIsAllowed(int r) {
if (r == 1) {
throw new IllegalArgumentException("message" + "concatenation" + r);
} else if (r == 2) {
throw new IllegalArgumentException("message" + "concatenation" + 2 * r);
} else {
throw new IllegalArgumentException("message" + "concatenation" + 3 * r);
}
}

public static final String NOT_IMPLEMENTED_MESSAGE = "Will do it on Tuesday!";

private int reportConstantsForArguments(int k) {
throw new RuntimeException("Will do it on Tuesday!"); // Noncompliant {{Use already-defined constant 'NOT_IMPLEMENTED_MESSAGE' instead of duplicating its value here.}}
}
}
Loading
Loading