Skip to content

Commit 3c7d0b5

Browse files
committed
[GR-37420] Re-enabling SpotBugs.
PullRequest: js/2375
2 parents 1d81ddd + 378f6cc commit 3c7d0b5

File tree

13 files changed

+76
-39
lines changed

13 files changed

+76
-39
lines changed

graal-js/mx.graal-js/suite.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
],
130130
"annotationProcessors" : ["truffle:TRUFFLE_DSL_PROCESSOR", "TRUFFLE_JS_FACTORY_PROCESSOR"],
131131
"jacoco" : "include",
132+
"spotbugs" : "true",
132133
"javaCompliance" : "11+",
133134
"checkstyleVersion" : "8.36.1",
134135
"workingSets" : "Truffle,JavaScript",
@@ -142,6 +143,7 @@
142143
],
143144
"jacoco" : "include",
144145
"checkstyle" : "com.oracle.truffle.js",
146+
"spotbugs" : "true",
145147
"javaCompliance" : "11+",
146148
"annotationProcessors" : ["truffle:TRUFFLE_DSL_PROCESSOR"],
147149
"workingSets" : "Truffle,JavaScript",
@@ -154,6 +156,7 @@
154156
"truffle:TRUFFLE_API",
155157
],
156158
"jacoco" : "include",
159+
"spotbugs" : "true",
157160
"javaCompliance" : "11+",
158161
"checkstyleVersion" : "8.36.1",
159162
"workingSets" : "Truffle,JavaScript",
@@ -168,6 +171,7 @@
168171
],
169172
"jacoco" : "include",
170173
"checkstyle" : "com.oracle.truffle.js",
174+
"spotbugs" : "true",
171175
"javaCompliance" : "11+",
172176
"workingSets" : "Truffle,JavaScript",
173177
},
@@ -178,6 +182,7 @@
178182
"dependencies" : [],
179183
"jacoco" : "include",
180184
"checkstyle" : "com.oracle.truffle.js",
185+
"spotbugs" : "true",
181186
"javaCompliance" : "11+",
182187
"workingSets" : "Truffle,JavaScript",
183188
},
@@ -190,6 +195,7 @@
190195
],
191196
"jacoco" : "include",
192197
"checkstyle" : "com.oracle.truffle.js",
198+
"spotbugs" : "true",
193199
"javaCompliance" : "11+",
194200
"workingSets" : "Truffle,JavaScript",
195201
},
@@ -202,6 +208,7 @@
202208
],
203209
"jacoco" : "include",
204210
"checkstyle" : "com.oracle.truffle.js",
211+
"spotbugs" : "true",
205212
"javaCompliance" : "11+",
206213
"workingSets" : "Truffle,JavaScript",
207214
},
@@ -219,6 +226,7 @@
219226
],
220227
"jacoco" : "include",
221228
"checkstyle" : "com.oracle.truffle.js",
229+
"spotbugs" : "true",
222230
"javaCompliance" : "11+",
223231
"workingSets" : "Truffle,JavaScript",
224232
},
@@ -228,8 +236,8 @@
228236
"sourceDirs" : ["src"],
229237
"dependencies" : [],
230238
"jacoco" : "include",
231-
"findbugs" : "false",
232-
# checkstyle and findbugs turned off to keep the source aligned
239+
"spotbugs" : "false",
240+
# checkstyle and spotbugs turned off to keep the source aligned
233241
# with the original nashorn version as much as possible
234242
"javaCompliance" : "11+",
235243
"workingSets" : "Truffle,JavaScript",
@@ -245,6 +253,7 @@
245253
],
246254
"jacoco" : "include",
247255
"checkstyle" : "com.oracle.truffle.js",
256+
"spotbugs" : "true",
248257
"javaCompliance" : "11+",
249258
"workingSets" : "Truffle,JavaScript",
250259
},
@@ -265,6 +274,7 @@
265274
],
266275
"annotationProcessors" : ["truffle:TRUFFLE_DSL_PROCESSOR"],
267276
"checkstyle" : "com.oracle.truffle.js",
277+
"spotbugs" : "true",
268278
"javaCompliance" : "11+",
269279
"workingSets" : "Truffle,JavaScript",
270280
"testProject" : True,
@@ -280,6 +290,7 @@
280290
],
281291
"annotationProcessors" : ["truffle:TRUFFLE_DSL_PROCESSOR"],
282292
"checkstyle" : "com.oracle.truffle.js",
293+
"spotbugs" : "true",
283294
"javaCompliance" : "11+",
284295
"workingSets" : "Truffle,JavaScript",
285296
"testProject" : True,
@@ -294,6 +305,7 @@
294305
],
295306
"annotationProcessors" : ["truffle:TRUFFLE_DSL_PROCESSOR"],
296307
"checkstyle" : "com.oracle.truffle.js",
308+
"spotbugs" : "true",
297309
"javaCompliance" : "11+",
298310
"workingSets" : "Truffle,JavaScript",
299311
"testProject" : True,
@@ -310,6 +322,7 @@
310322
],
311323
"jacoco" : "include",
312324
"checkstyle" : "com.oracle.truffle.js",
325+
"spotbugs" : "true",
313326
"javaCompliance" : "11+",
314327
"workingSets" : "Truffle,JavaScript",
315328
},
@@ -328,6 +341,7 @@
328341
"java.desktop",
329342
],
330343
"checkstyle" : "com.oracle.truffle.js",
344+
"spotbugs" : "true",
331345
"javaCompliance" : "11+",
332346
"workingSets" : "Truffle,JavaScript",
333347
"testProject" : True,
@@ -342,6 +356,7 @@
342356
"mx:JMH_1_21"
343357
],
344358
"checkstyle" : "com.oracle.truffle.js",
359+
"spotbugs" : "true",
345360
"javaCompliance" : "11+",
346361
"annotationProcessors" : ["mx:JMH_1_21"],
347362
"spotbugsIgnoresGenerated" : True,
@@ -361,6 +376,7 @@
361376
],
362377
"annotationProcessors" : ["truffle:TRUFFLE_DSL_PROCESSOR"],
363378
"checkstyle" : "com.oracle.truffle.js",
379+
"spotbugs" : "true",
364380
"javaCompliance" : "11+",
365381
"workingSets" : "Truffle,JavaScript,Test",
366382
"testProject" : True,
@@ -374,6 +390,7 @@
374390
"sdk:POLYGLOT_TCK"
375391
],
376392
"checkstyle" : "com.oracle.truffle.js",
393+
"spotbugs" : "true",
377394
"javaCompliance" : "11+",
378395
"workingSets" : "Truffle,JavaScript,Test",
379396
"testProject" : True,

graal-js/src/com.oracle.truffle.js.scriptengine.test/src/com/oracle/truffle/js/scriptengine/test/TestEngine.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
package com.oracle.truffle.js.scriptengine.test;
4242

4343
import static org.junit.Assert.assertEquals;
44-
import static org.junit.Assert.assertSame;
4544
import static org.junit.Assert.assertTrue;
4645
import static org.junit.Assert.fail;
4746

@@ -236,7 +235,7 @@ public void moduleWithDependency() throws IOException, ScriptException {
236235

237236
Object result = engine.eval(mainModule);
238237

239-
assertSame(42, ((Number) result).intValue());
238+
assertEquals(42, ((Number) result).intValue());
240239
}
241240

242241
@Test

graal-js/src/com.oracle.truffle.js.scriptengine.test/src/com/oracle/truffle/js/scriptengine/test/TestInvocable.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -54,6 +54,8 @@
5454

5555
import org.junit.Test;
5656

57+
import com.oracle.truffle.js.runtime.SuppressFBWarnings;
58+
5759
public class TestInvocable {
5860

5961
private final ScriptEngineManager manager = new ScriptEngineManager();
@@ -143,6 +145,7 @@ public void getInterfaceNotAnInterface() throws Exception {
143145
inv.getInterface(obj, String.class);
144146
}
145147

148+
@SuppressFBWarnings(value = "NP_NULL_PARAM_DEREF", justification = "Testing the refusal of null")
146149
@Test(expected = IllegalArgumentException.class)
147150
public void getInterfaceNull1() throws Exception {
148151
ScriptEngine engine = getEngine();

graal-js/src/com.oracle.truffle.js.test.instrumentation/src/com/oracle/truffle/js/test/instrumentation/SwitchStatementTest.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -54,19 +54,23 @@ public class SwitchStatementTest extends FineGrainedAccessTest {
5454

5555
private boolean savedSwitchConfigValue;
5656

57+
private static void setOptimizeNoFallthroughSwitch(boolean value) {
58+
JSConfig.OptimizeNoFallthroughSwitch = value;
59+
}
60+
5761
@Before
5862
public void before() {
5963
savedSwitchConfigValue = JSConfig.OptimizeNoFallthroughSwitch;
6064
}
6165

6266
@After
6367
public void after() {
64-
JSConfig.OptimizeNoFallthroughSwitch = savedSwitchConfigValue;
68+
setOptimizeNoFallthroughSwitch(savedSwitchConfigValue);
6569
}
6670

6771
@Test
6872
public void desugaredSwitchBreak() {
69-
JSConfig.OptimizeNoFallthroughSwitch = true;
73+
setOptimizeNoFallthroughSwitch(true);
7074
// Graal.js converts certain switch statements to if-then-else chains. This generates nested
7175
// events.
7276
String src = "var a = 42;" +
@@ -105,7 +109,7 @@ public void desugaredSwitchBreak() {
105109

106110
@Test
107111
public void normalSwitchBreak() {
108-
JSConfig.OptimizeNoFallthroughSwitch = false;
112+
setOptimizeNoFallthroughSwitch(false);
109113
String src = "var a = 42;" +
110114
"switch (a) {\n" +
111115
" case 1:" +
@@ -137,7 +141,7 @@ public void normalSwitchBreak() {
137141

138142
@Test
139143
public void desugaredSwitchDefault() {
140-
JSConfig.OptimizeNoFallthroughSwitch = true;
144+
setOptimizeNoFallthroughSwitch(true);
141145
// Graal.js converts certain switch statements to if-then-else chains. This generates nested
142146
// events.
143147
String src = "var a = 42;" +
@@ -176,7 +180,7 @@ public void desugaredSwitchDefault() {
176180

177181
@Test
178182
public void normalSwitchDefault() {
179-
JSConfig.OptimizeNoFallthroughSwitch = false;
183+
setOptimizeNoFallthroughSwitch(false);
180184
String src = "var a = 42;" +
181185
"switch (a) {\n" +
182186
" case 1:" +
@@ -269,7 +273,7 @@ public void defaultSwitchNode() {
269273

270274
@Test
271275
public void desugaredSwitchNoBreak() {
272-
JSConfig.OptimizeNoFallthroughSwitch = true;
276+
setOptimizeNoFallthroughSwitch(true);
273277
String src = "var a = 42;" +
274278
"switch (a) {" +
275279
" case 1:" +
@@ -288,7 +292,7 @@ public void desugaredSwitchNoBreak() {
288292

289293
@Test
290294
public void normalSwitchNoBreak() {
291-
JSConfig.OptimizeNoFallthroughSwitch = false;
295+
setOptimizeNoFallthroughSwitch(false);
292296
String src = "var a = 42;" +
293297
"switch (a) {" +
294298
" case 1:" +

graal-js/src/com.oracle.truffle.js.test.instrumentation/src/com/oracle/truffle/js/test/instrumentation/sourcesections/SwitchStatementsTest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -50,19 +50,23 @@ public class SwitchStatementsTest extends SourceSectionInstrumentationTest {
5050

5151
private boolean savedSwitchConfigValue;
5252

53+
private static void setOptimizeNoFallthroughSwitch(boolean value) {
54+
JSConfig.OptimizeNoFallthroughSwitch = value;
55+
}
56+
5357
@Before
5458
public void before() {
5559
savedSwitchConfigValue = JSConfig.OptimizeNoFallthroughSwitch;
5660
}
5761

5862
@After
5963
public void after() {
60-
JSConfig.OptimizeNoFallthroughSwitch = savedSwitchConfigValue;
64+
setOptimizeNoFallthroughSwitch(savedSwitchConfigValue);
6165
}
6266

6367
@Test
6468
public void basicDeclarations() {
65-
JSConfig.OptimizeNoFallthroughSwitch = true;
69+
setOptimizeNoFallthroughSwitch(true);
6670
String src = "var bar = 0;" +
6771
"switch ('foo') {" +
6872
"case 'bar':" +

graal-js/src/com.oracle.truffle.js.test.threading/src/com/oracle/truffle/js/test/threading/ConcurrentAccess.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -192,18 +192,19 @@ public void concurrentEvalsWithEnter() {
192192
startGate.await();
193193
try {
194194
for (int it = 0; it < 100000; it++) {
195+
contextLock.lock();
195196
try {
196197
try {
197-
contextLock.lock();
198198
cx.enter();
199199
String encoded = json.execute(42, 43).asString();
200200
assertEquals("{\"x\":42,\"y\":43}", encoded);
201201
} finally {
202202
cx.leave();
203-
contextLock.unlock();
204203
}
205204
} catch (IllegalStateException e) {
206205
hadException.set(true);
206+
} finally {
207+
contextLock.unlock();
207208
}
208209
}
209210
} finally {

graal-js/src/com.oracle.truffle.js.test/src/com/oracle/truffle/js/test/builtins/CommonJSRequireTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -189,7 +189,10 @@ private static String logicalAbsolutePath(Path path) {
189189
String pathStr = path.toAbsolutePath().toString();
190190
if (System.getProperty("os.name").startsWith("Windows")) {
191191
// On Windows we support logical Unix-like paths
192-
pathStr = pathStr.replaceFirst(path.getRoot().toString() + "\\", "/");
192+
Path root = path.getRoot();
193+
if (root != null) {
194+
pathStr = pathStr.replaceFirst(root.toString() + "\\", "/");
195+
}
193196
pathStr = pathStr.replace("\\", "/");
194197
}
195198
return pathStr;

graal-js/src/com.oracle.truffle.js.test/src/com/oracle/truffle/js/test/interop/JSProxyTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -42,7 +42,6 @@
4242

4343
import static com.oracle.truffle.js.lang.JavaScriptLanguage.ID;
4444
import static org.junit.Assert.assertEquals;
45-
import static org.junit.Assert.assertSame;
4645
import static org.junit.Assert.assertTrue;
4746

4847
import java.util.Collections;
@@ -188,7 +187,7 @@ public void testForeignGetTrap() {
188187
"return proxy.foo;\n" +
189188
"})").execute((ProxyExecutable) args -> 42);
190189
assertTrue(value.isNumber());
191-
assertSame(42, value.asInt());
190+
assertEquals(42, value.asInt());
192191
}
193192
}
194193

@@ -247,7 +246,7 @@ public void testForeignApplyTrap() {
247246
return 42;
248247
});
249248
assertTrue(value.isNumber());
250-
assertSame(42, value.asInt());
249+
assertEquals(42, value.asInt());
251250
}
252251
}
253252

0 commit comments

Comments
 (0)