Skip to content

Commit 86227ca

Browse files
committed
Suppress field not initialized warning + improve readability
1 parent ce78750 commit 86227ca

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

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

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

1212
import java.util.ArrayList;
1313

14+
import org.truffleruby.annotations.SuppressFBWarnings;
1415
import org.truffleruby.cext.CapturedException;
1516
import org.truffleruby.cext.ValueWrapper;
1617
import org.truffleruby.core.array.ArrayUtils;
@@ -43,7 +44,7 @@ protected static final class ExtensionCallStackEntry {
4344

4445
private final ExtensionCallStackEntry previous;
4546
ValueWrapper preservedObject;
46-
ArrayList<ValueWrapper> preservedObjects;
47+
@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR") ArrayList<ValueWrapper> preservedObjectList;
4748
private final boolean keywordsGiven;
4849
private Object specialVariables;
4950
private final Object block;
@@ -79,7 +80,11 @@ public boolean hasKeptObjects() {
7980
}
8081

8182
public boolean hasSingleKeptObject() {
82-
return current.preservedObject != null && current.preservedObjects == null;
83+
return current.preservedObject != null && current.preservedObjectList == null;
84+
}
85+
86+
public boolean isPreservedObjectListInitialized() {
87+
return current.preservedObjectList != null;
8388
}
8489

8590
public void markOnExitObject(ValueWrapper value) {

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.oracle.truffle.api.dsl.GenerateCached;
1313
import com.oracle.truffle.api.dsl.GenerateInline;
1414
import com.oracle.truffle.api.dsl.NeverDefault;
15+
import com.oracle.truffle.api.dsl.NonIdempotent;
1516
import com.oracle.truffle.api.nodes.Node;
1617
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
1718
import org.truffleruby.cext.ValueWrapper;
@@ -52,20 +53,24 @@ static void keepCreatingList(Node node, ValueWrapper object,
5253
}
5354
}
5455

55-
@Specialization(guards = { "stack.hasKeptObjects()", "!stack.hasSingleKeptObject()" })
56+
@Specialization(guards = {
57+
"stack.isPreservedObjectListInitialized()",
58+
"stack.hasKeptObjects()",
59+
"!stack.hasSingleKeptObject()" })
5660
@TruffleBoundary
5761
static void keepAddingToList(Node node, ValueWrapper object,
5862
@Bind("getStack(node)") ExtensionCallStack stack) {
59-
stack.current.preservedObjects.add(object);
63+
stack.current.preservedObjectList.add(object);
6064
}
6165

6266
@TruffleBoundary
6367
private static void createKeptList(ValueWrapper object, ExtensionCallStack stack) {
64-
stack.current.preservedObjects = new ArrayList<>();
65-
stack.current.preservedObjects.add(stack.current.preservedObject);
66-
stack.current.preservedObjects.add(object);
68+
stack.current.preservedObjectList = new ArrayList<>();
69+
stack.current.preservedObjectList.add(stack.current.preservedObject);
70+
stack.current.preservedObjectList.add(object);
6771
}
6872

73+
@NonIdempotent
6974
protected static ExtensionCallStack getStack(Node node) {
7075
return getLanguage(node).getCurrentThread().getCurrentFiber().extensionCallStack;
7176
}

0 commit comments

Comments
 (0)