Skip to content

Commit 2c8fdd3

Browse files
authored
Merge branch 'master' into fix2628
2 parents c50cda0 + bb2d705 commit 2c8fdd3

File tree

8 files changed

+72
-5
lines changed

8 files changed

+72
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Currently the versioning policy of this project follows [Semantic Versioning v2.
1212
- Fixed missing null checks ([[#2629](https://github.com/spotbugs/spotbugs/issues/2629)])
1313
- Disabled DontReusePublicIdentifiers due to the high false positives rate ([[#2627](https://github.com/spotbugs/spotbugs/issues/2627)])
1414
- Removed signature of methods using UTF-8 in DefaultEncodingDetector ([[#2634](https://github.com/spotbugs/spotbugs/issues/2634)])
15+
- Fix exception escapes when calling functions of JUnit Assert or Assertions ([[#2640](https://github.com/spotbugs/spotbugs/issues/2640)])
16+
- Fixed an error in the SARIF export when a bug annotation is missing ([[#2632](https://github.com/spotbugs/spotbugs/issues/2632)])
1517
- Fixed false positive RV_EXCEPTION_NOT_THROWN when asserting to exception throws ([[#2628](https://github.com/spotbugs/spotbugs/issues/2628)])
1618

1719
## 4.8.0 - 2023-10-11

gradle/jacoco.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apply plugin: "jacoco"
22

33
jacoco {
4-
toolVersion = "0.8.10"
4+
toolVersion = "0.8.11"
55
}
66

77
jacocoTestReport {

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[versions]
22
asm = "9.6"
33
guice = "5.1.0"
4-
log4j = "2.20.0"
4+
log4j = "2.21.0"
55

66
[libraries]
77
asm = { module = "org.ow2.asm:asm", version.ref = "asm" }
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package edu.umd.cs.findbugs.detect;
2+
3+
import edu.umd.cs.findbugs.AbstractIntegrationTest;
4+
import org.junit.jupiter.api.Assertions;
5+
import org.junit.jupiter.api.Test;
6+
7+
class Issue2640Test extends AbstractIntegrationTest {
8+
@Test
9+
void testIssue() {
10+
Assertions.assertDoesNotThrow(() -> performAnalysis("ghIssues/Issue2640.class"));
11+
}
12+
}

spotbugs-tests/src/test/java/edu/umd/cs/findbugs/sarif/SarifBugReporterTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,45 @@ void testRuleWithArguments() {
160160
assertThat(arguments.get(0).getAsInt(), is(10));
161161
}
162162

163+
164+
165+
@Test
166+
void testRuleWithInvalidArguments() {
167+
// given
168+
final String EXPECTED_BUG_TYPE = "BUG_TYPE";
169+
final int EXPECTED_PRIORITY = Priorities.NORMAL_PRIORITY;
170+
final String EXPECTED_DESCRIPTION = "describing about this bug type...";
171+
BugPattern bugPattern = new BugPattern(EXPECTED_BUG_TYPE, "abbrev", "category", false, EXPECTED_DESCRIPTION,
172+
"describing about this bug type with value {1234}...", "detailText", null, 0);
173+
DetectorFactoryCollection.instance().registerBugPattern(bugPattern);
174+
175+
// when
176+
reporter.reportBug(new BugInstance(bugPattern.getType(), bugPattern.getPriorityAdjustment()).addInt(10).addClass("the/target/Class"));
177+
reporter.finish();
178+
179+
// then
180+
String json = writer.toString();
181+
JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class);
182+
JsonObject run = jsonObject.getAsJsonArray("runs").get(0).getAsJsonObject();
183+
JsonArray rules = run.getAsJsonObject("tool").getAsJsonObject("driver").getAsJsonArray("rules");
184+
JsonArray results = run.getAsJsonArray("results");
185+
186+
assertThat(rules.size(), is(1));
187+
JsonObject rule = rules.get(0).getAsJsonObject();
188+
assertThat(rule.get("id").getAsString(), is(bugPattern.getType()));
189+
String defaultText = rule.getAsJsonObject("messageStrings").getAsJsonObject("default").get("text").getAsString();
190+
assertThat(defaultText, is("describing about this bug type with value {0}..."));
191+
192+
assertThat(results.size(), is(1));
193+
JsonObject result = results.get(0).getAsJsonObject();
194+
assertThat(result.get("ruleId").getAsString(), is(bugPattern.getType()));
195+
JsonObject message = result.getAsJsonObject("message");
196+
assertThat(message.get("id").getAsString(), is("default"));
197+
assertThat(message.get("text").getAsString(), is(bugPattern.getShortDescription()));
198+
JsonArray arguments = message.getAsJsonArray("arguments");
199+
assertThat(arguments.get(0).getAsString(), is("?>?1234/2???"));
200+
}
201+
163202
@Test
164203
void testMissingClassNotification() {
165204
ClassDescriptor classDescriptor = DescriptorFactory.instance().getClassDescriptor("com/github/spotbugs/MissingClass");

spotbugs/src/main/java/edu/umd/cs/findbugs/detect/DumbMethods.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ public void sawOpcode(int seen) {
169169
}
170170

171171
if (seen == Const.INVOKESTATIC && ("junit/framework/Assert".equals(getClassConstantOperand()) || "org/junit/Assert".equals(
172-
getClassConstantOperand()) || "org/junit/jupiter/api/Assertion".equals(getClassConstantOperand())
173-
&& "assertNotNull".equals(getNameConstantOperand()))) {
172+
getClassConstantOperand()) || "org/junit/jupiter/api/Assertion".equals(getClassConstantOperand()))
173+
&& "assertNotNull".equals(getNameConstantOperand())) {
174174

175175
OpcodeStack.Item item = stack.getStackItem(0);
176176
Object o = item.getConstant();

spotbugs/src/main/java/edu/umd/cs/findbugs/sarif/Placeholder.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ class Placeholder {
2828

2929
@NonNull
3030
String toArgument(List<? extends BugAnnotation> bugAnnotations, @Nullable ClassAnnotation primaryClass) {
31-
return bugAnnotations.get(index).format(key, primaryClass);
31+
if (index < 0) {
32+
return "?<?" + index + "/" + bugAnnotations.size() + "???";
33+
} else if (index >= bugAnnotations.size()) {
34+
return "?>?" + index + "/" + bugAnnotations.size() + "???";
35+
} else {
36+
return bugAnnotations.get(index).format(key, primaryClass);
37+
}
3238
}
3339
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package ghIssues;
2+
3+
public class Issue2640 {
4+
public void testUnreachableCode() {
5+
org.junit.Assert.fail();
6+
System.err.println("Not reachable code");
7+
}
8+
}

0 commit comments

Comments
 (0)