Skip to content

Commit d922087

Browse files
committed
Address SpotBugs warnings
1 parent 4cae1d0 commit d922087

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+102
-92
lines changed

mx.truffleruby/spotbugs-filters.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
<Bug pattern="RC_REF_COMPARISON_BAD_PRACTICE_BOOLEAN" />
2525
<Bug pattern="BX_UNBOXING_IMMEDIATELY_REBOXED" /> <!-- used as a way to assert the type -->
2626
<Bug pattern="PZLA_PREFER_ZERO_LENGTH_ARRAYS" />
27+
<Bug pattern="ES_COMPARING_PARAMETER_STRING_WITH_EQ" />
28+
<Bug pattern="ES_COMPARING_STRINGS_WITH_EQ" />
2729
</Or>
2830
</Not>
2931
</Match>

src/launcher/java/org/truffleruby/launcher/RubyLauncher.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import java.io.PrintStream;
1313
import java.io.IOException;
14+
import java.nio.charset.StandardCharsets;
1415
import java.util.ArrayList;
1516
import java.util.Arrays;
1617
import java.util.Collections;
@@ -195,7 +196,7 @@ protected boolean runLauncherAction() {
195196
.redirectOutput(Redirect.INHERIT) // set the output of the pager to the terminal and not a pipe
196197
.redirectError(Redirect.INHERIT) // set the error of the pager to the terminal and not a pipe
197198
.start();
198-
PrintStream out = new PrintStream(process.getOutputStream());
199+
PrintStream out = new PrintStream(process.getOutputStream(), false, StandardCharsets.UTF_8);
199200

200201
setOutput(out);
201202
boolean code = super.runLauncherAction();

src/main/java/org/truffleruby/RubyContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ private void dispose() {
528528
RubyLanguage.LOGGER.info(
529529
"Total VALUE object to native conversions: " + getValueWrapperManager().totalHandleAllocations());
530530
}
531-
valueWrapperManager.freeAllBlocksInMap(language);
531+
valueWrapperManager.freeAllBlocksInMap();
532532
}
533533

534534
public boolean isPreInitializing() {

src/main/java/org/truffleruby/RubyLanguage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ private RubyThread getOrCreateForeignThread(RubyContext context, Thread thread)
256256
public Thread cleanerThread = null;
257257
@CompilationFinal public Cleaner cleaner = null;
258258

259-
public volatile ValueWrapperManager.HandleBlockWeakReference[] handleBlockSharedMap = new ValueWrapperManager.HandleBlockWeakReference[0];
259+
@SuppressFBWarnings("VO_VOLATILE_REFERENCE_TO_ARRAY") public volatile ValueWrapperManager.HandleBlockWeakReference[] handleBlockSharedMap = new ValueWrapperManager.HandleBlockWeakReference[0];
260260
public final ValueWrapperManager.HandleBlockAllocator handleBlockAllocator = new ValueWrapperManager.HandleBlockAllocator();
261261

262262
@CompilationFinal public LanguageOptions options;

src/main/java/org/truffleruby/cext/ValueWrapperManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,8 @@ private HandleBlock getBlockFromMap(int index, RubyLanguage language) {
139139
return ref.get();
140140
}
141141

142-
public void freeAllBlocksInMap(RubyLanguage language) {
142+
public void freeAllBlocksInMap() {
143143
HandleBlockWeakReference[] map = blockMap;
144-
HandleBlockAllocator allocator = language.handleBlockAllocator;
145144

146145
for (HandleBlockWeakReference ref : map) {
147146
if (ref == null) {

src/main/java/org/truffleruby/collections/ConcurrentOperations.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.truffleruby.collections;
1111

1212
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
13+
import org.truffleruby.annotations.SuppressFBWarnings;
1314

1415
import java.util.Map;
1516
import java.util.concurrent.ConcurrentHashMap;
@@ -59,6 +60,7 @@ public static <K, V> boolean replace(Map<K, V> map, K key, V oldValue, V newValu
5960
* prefers the signal and just returns, it does {@code Thread.currentThread().interrupt()} to let us know there was
6061
* an interrupt too. In any case, if there was any interrupt we want to throw InterruptedException, regardless of
6162
* what the implementation prefers. */
63+
@SuppressFBWarnings("WA_AWAIT_NOT_IN_LOOP")
6264
public static void awaitAndCheckInterrupt(Condition condition) throws InterruptedException {
6365
// Checkstyle: stop
6466
condition.await();

src/main/java/org/truffleruby/collections/IntHashMap.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
***** END LICENSE BLOCK *****/
2929
package org.truffleruby.collections;
3030

31+
import org.truffleruby.annotations.SuppressFBWarnings;
32+
3133
import java.util.AbstractSet;
3234
import java.util.Iterator;
3335
import java.util.NoSuchElementException;
@@ -228,6 +230,7 @@ public boolean hasNext() {
228230
return next != null;
229231
}
230232

233+
@SuppressFBWarnings("SA_FIELD_SELF_ASSIGNMENT")
231234
Entry<V> nextEntry() {
232235
Entry<V> e = next;
233236
if (e == null) {

src/main/java/org/truffleruby/collections/SharedIndicesMap.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.oracle.truffle.api.CompilerAsserts;
2424
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
2525
import com.oracle.truffle.api.dsl.NeverDefault;
26+
import org.truffleruby.annotations.SuppressFBWarnings;
2627

2728
/** An append-only map of names or identifiers to indices. The map is stored in {@link org.truffleruby.RubyLanguage} and
2829
* each {@link org.truffleruby.RubyContext} have separate {@link ContextArray}s. This enables looking up names and
@@ -93,6 +94,7 @@ protected T getSlowPath(int index) {
9394
}
9495
}
9596

97+
@SuppressFBWarnings("IS2_INCONSISTENT_SYNC")
9698
@TruffleBoundary
9799
public boolean contains(int index) {
98100
assert index <= sharedIndicesMap.size();

src/main/java/org/truffleruby/core/MarkingService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected static final class ExtensionCallStackEntry {
5050
private CapturedException capturedException;
5151
private ValueWrapper markOnExitObject;
5252
private ArrayList<ValueWrapper> markOnExitObjects;
53-
private Object[] marks;
53+
private Object[] marks = null;
5454
private int marksIndex = 0;
5555

5656
private ExtensionCallStackEntry(

src/main/java/org/truffleruby/core/TruffleSystemNodes.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
package org.truffleruby.core;
4040

4141
import java.io.IOException;
42+
import java.lang.invoke.VarHandle;
4243
import java.lang.management.ManagementFactory;
4344
import java.nio.file.NoSuchFileException;
4445
import java.util.Set;
@@ -51,6 +52,7 @@
5152
import com.sun.management.ThreadMXBean;
5253
import org.truffleruby.RubyLanguage;
5354
import org.truffleruby.annotations.CoreMethod;
55+
import org.truffleruby.annotations.SuppressFBWarnings;
5456
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
5557
import org.truffleruby.builtins.CoreMethodNode;
5658
import org.truffleruby.annotations.CoreModule;
@@ -281,14 +283,18 @@ protected int availableProcessors() {
281283

282284
@CoreMethod(names = "allocated_bytes_of_current_thread", onSingleton = true)
283285
public abstract static class AllocatedBytesNode extends CoreMethodArrayArgumentsNode {
286+
284287
private static ThreadMXBean bean;
285288

289+
@SuppressFBWarnings("LI_LAZY_INIT_STATIC")
286290
@TruffleBoundary
287291
@Specialization
288292
protected static long allocatedBytes() {
289293
if (bean == null) {
290-
bean = (ThreadMXBean) ManagementFactory.getThreadMXBean();
291-
bean.setThreadAllocatedMemoryEnabled(true);
294+
var threadMXBean = (ThreadMXBean) ManagementFactory.getThreadMXBean();
295+
threadMXBean.setThreadAllocatedMemoryEnabled(true);
296+
VarHandle.storeStoreFence();
297+
bean = threadMXBean;
292298
}
293299

294300
return bean.getCurrentThreadAllocatedBytes();

0 commit comments

Comments
 (0)