Skip to content

Commit aa91329

Browse files
committed
[GR-13337] Enable SpotBugs.
PullRequest: fastr/1915
2 parents 83fbbb8 + d25c9ef commit aa91329

File tree

81 files changed

+397
-314
lines changed

Some content is hidden

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

81 files changed

+397
-314
lines changed

ci_common/common.hocon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ gateStyle : ${common} {
198198
ECLIPSE_EXE : "$ECLIPSE/eclipse"
199199
}
200200
run : [
201-
${gateCmd} ["Versions,JDKReleaseInfo,Pylint,Canonicalization Check,BuildJavaWithJavac,IDEConfigCheck,CodeFormatCheck,Checkstyle,Copyright check,UnitTests: ExpectedTestOutput file check"]
201+
${gateCmd} ["Versions,JDKReleaseInfo,Pylint,Canonicalization Check,BuildJavaWithJavac,SpotBugs,IDEConfigCheck,CodeFormatCheck,Checkstyle,Copyright check,UnitTests: ExpectedTestOutput file check"]
202202
["mx", "clean", "--no-native"]
203203
${gateCmd} ["BuildWithEcj"]
204204
]

com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/shell/REmbedded.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.oracle.truffle.r.launcher.RStartParams;
3636
import com.oracle.truffle.r.runtime.RSource.Internal;
3737
import com.oracle.truffle.r.runtime.RSuicide;
38+
import com.oracle.truffle.r.runtime.SuppressFBWarnings;
3839
import com.oracle.truffle.r.runtime.Utils;
3940
import com.oracle.truffle.r.runtime.context.RContext;
4041

@@ -69,6 +70,7 @@ public class REmbedded {
6970
* initialize FastR as we cannot do that until the embedding system has had a chance to adjust
7071
* the {@link RStartParams}, which happens after this call returns.
7172
*/
73+
@SuppressFBWarnings(value = "LI_LAZY_INIT_UPDATE_STATIC", justification = "one-time initialization")
7274
private static void initializeR(String[] args, boolean initMainLoop) {
7375
assert context == null;
7476
RContext.setEmbedded();

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_Context.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import com.oracle.truffle.r.ffi.impl.llvm.TruffleLLVM_DLL.ParsedLLVM_IR;
3838
import com.oracle.truffle.r.runtime.REnvVars;
3939
import com.oracle.truffle.r.runtime.RInternalError;
40+
import com.oracle.truffle.r.runtime.Utils;
4041
import com.oracle.truffle.r.runtime.context.RContext;
4142
import com.oracle.truffle.r.runtime.context.RContext.ContextState;
4243
import com.oracle.truffle.r.runtime.ffi.BaseRFFI;
@@ -134,10 +135,10 @@ public TruffleObject lookupNativeFunction(NativeFunction function) {
134135
CompilerAsserts.neverPartOfCompilation();
135136
if (!nativeFunctions.containsKey(function)) {
136137
TruffleObject[] lookupObjects = new TruffleObject[0];
137-
if (function.getLibrary() == NativeFunction.baseLibrary()) {
138+
if (Utils.identityEquals(function.getLibrary(), NativeFunction.baseLibrary())) {
138139
TruffleObject lookupObject = (TruffleObject) ((LLVM_Handle) DLL.getRdllInfo().handle).parsedIRs[0].lookupObject;
139140
lookupObjects = new TruffleObject[]{lookupObject};
140-
} else if (function.getLibrary() == NativeFunction.anyLibrary()) {
141+
} else if (Utils.identityEquals(function.getLibrary(), NativeFunction.anyLibrary())) {
141142
DLLInfo dllInfo = DLL.findLibraryContainingSymbol(RContext.getInstance(), function.getCallName());
142143
if (dllInfo == null) {
143144
throw RInternalError.shouldNotReachHere("Could not find library containing symbol " + function.getCallName());

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/llvm/TruffleLLVM_DownCallNodeFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import com.oracle.truffle.api.nodes.ExplodeLoop;
3838
import com.oracle.truffle.api.nodes.RootNode;
3939
import com.oracle.truffle.r.runtime.RInternalError;
40+
import com.oracle.truffle.r.runtime.Utils;
4041
import com.oracle.truffle.r.runtime.data.RFunction;
4142
import com.oracle.truffle.r.runtime.ffi.DLL;
4243
import com.oracle.truffle.r.runtime.ffi.DLL.DLLInfo;
@@ -68,9 +69,9 @@ protected TruffleObject getTarget(NativeFunction fn) {
6869
CompilerAsserts.neverPartOfCompilation();
6970
String library = fn.getLibrary();
7071
DLLInfo dllInfo = null;
71-
if (library == baseLibrary()) {
72+
if (Utils.identityEquals(library, baseLibrary())) {
7273
dllInfo = DLL.getRdllInfo();
73-
} else if (library != anyLibrary()) {
74+
} else if (!Utils.identityEquals(library, anyLibrary())) {
7475
dllInfo = DLL.findLibrary(library);
7576
}
7677
SymbolHandle result = DLL.findSymbol(fn.getCallName(), dllInfo);

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/mixed/TruffleMixed_Context.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public void afterUpcall(boolean canRunGc, Type rffiType) {
125125
@Override
126126
public long beforeDowncall(Type rffiType) {
127127
Type actualRffiType = rffiType == null ? Type.LLVM : rffiType;
128+
assert rffiType != null;
128129
switch (rffiType) {
129130
case LLVM:
130131
return llvmContext.beforeDowncall(actualRffiType);

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Context.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.oracle.truffle.r.ffi.impl.nfi.TruffleNFI_DLL.NFIHandle;
4343
import com.oracle.truffle.r.ffi.impl.upcalls.Callbacks;
4444
import com.oracle.truffle.r.runtime.RInternalError;
45+
import com.oracle.truffle.r.runtime.Utils;
4546
import com.oracle.truffle.r.runtime.context.FastROptions;
4647
import static com.oracle.truffle.r.runtime.context.FastROptions.TraceNativeCalls;
4748
import com.oracle.truffle.r.runtime.context.RContext;
@@ -143,9 +144,9 @@ public TruffleObject lookupNativeFunction(NativeFunction function) {
143144
CompilerAsserts.neverPartOfCompilation();
144145
if (!nativeFunctions.containsKey(function)) {
145146
TruffleObject dllInfo;
146-
if (function.getLibrary() == NativeFunction.baseLibrary()) {
147+
if (Utils.identityEquals(function.getLibrary(), NativeFunction.baseLibrary())) {
147148
dllInfo = TruffleNFI_Context.getInstance().defaultLibrary;
148-
} else if (function.getLibrary() == NativeFunction.anyLibrary()) {
149+
} else if (Utils.identityEquals(function.getLibrary(), NativeFunction.anyLibrary())) {
149150
DLLInfo lib = DLL.findLibraryContainingSymbol(RContext.getInstance(), function.getCallName());
150151
if (lib == null) {
151152
throw RInternalError.shouldNotReachHere("Could not find library containing symbol " + function.getCallName());

com.oracle.truffle.r.ffi.processor/src/com/oracle/truffle/r/ffi/processor/FFIProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ private void generateCallClass(ExecutableElement m) throws IOException {
379379
if (resultOwnerRHS != null) {
380380
w.append(" ctx.protectChild(resultOwner, resultRObj);\n");
381381
} else {
382-
if (returnKind != TypeKind.VOID) {
382+
if (returnKind != TypeKind.VOID && needsReturnWrap) {
383383
w.append(" if (resultRObj0 != resultRObj) {\n");
384384
w.append(" ctx.protectChild(resultRObj0, resultRObj);\n");
385385
w.append(" }\n");

com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/ConsoleHandler.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -114,7 +114,7 @@ public static ConsoleHandler createConsoleHandler(RCmdOptions options, Delegatin
114114

115115
/**
116116
* Get the R prompt.
117-
*
117+
*
118118
* @return the prompt
119119
*/
120120
public abstract String getPrompt();
@@ -182,7 +182,12 @@ public Object getMemberKeys() {
182182

183183
@Override
184184
public boolean hasMember(String key) {
185-
return key.contains(key);
185+
for (String k : keys) {
186+
if (k.equals(key)) {
187+
return true;
188+
}
189+
}
190+
return false;
186191
}
187192

188193
@Override

com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/remote/RemoteDevice.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import com.oracle.truffle.r.library.fastrGrid.device.NotSupportedImageFormatException;
4848
import com.oracle.truffle.r.runtime.REnvVars;
4949
import com.oracle.truffle.r.runtime.RInternalError;
50+
import com.oracle.truffle.r.runtime.SuppressFBWarnings;
5051

5152
public final class RemoteDevice implements GridDevice {
5253

@@ -125,6 +126,7 @@ public static RemoteDevice createWindowDevice(int width, int height) {
125126
}
126127
}
127128

129+
@SuppressFBWarnings(value = "LI_LAZY_INIT_UPDATE_STATIC", justification = "one-time initialization")
128130
private static Path javaCmd() {
129131
if (javaCmd == null) {
130132
String javaHome = System.getenv("JAVA_HOME");
@@ -139,6 +141,7 @@ private static Path javaCmd() {
139141
return javaCmd;
140142
}
141143

144+
@SuppressFBWarnings(value = "LI_LAZY_INIT_UPDATE_STATIC", justification = "one-time initialization")
142145
private static void checkQueueInited() {
143146
if (queueWorker == null) {
144147
Runnable queueWorkerRun = new Runnable() {
@@ -198,6 +201,7 @@ public void run() {
198201
}
199202
}
200203

204+
@SuppressFBWarnings(value = "LI_LAZY_INIT_STATIC", justification = "one-time initialization")
201205
private static boolean checkServerConnectable() {
202206
for (int i = SERVER_CONNECT_RETRIES - 1; i >= 0; i--) {
203207
if (serverProcess != null && !serverProcess.isAlive()) {
@@ -607,7 +611,7 @@ void finish(byte[] resultArg, Exception errorCauseArg) {
607611
assert (this.result == null) : "Result already assigned";
608612
byte[] resultArg2 = resultArg;
609613
if (resultArg2 != null) {
610-
assert (params[0] | RESULT_MASK) != 0 : "Attempt to assign result to non-result request";
614+
assert (params[0] & RESULT_MASK) != 0 : "Attempt to assign result to non-result request";
611615
} else {
612616
resultArg2 = EMPTY_RESULT;
613617
}

com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/methods/MethodsListDispatch.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Copyright (c) 1995-2012, The R Core Team
33
* Copyright (c) 2003, The R Foundation
4-
* Copyright (c) 2015, 2018, Oracle and/or its affiliates
4+
* Copyright (c) 2015, 2019, Oracle and/or its affiliates
55
*
66
* This program is free software; you can redistribute it and/or modify
77
* it under the terms of the GNU General Public License as published by
@@ -188,7 +188,7 @@ protected Object callGetClassFromCache(RAbstractStringVector klass, REnvironment
188188
Object valAttrObj = attributableValue.getAttributes() == null ? null : valPckgAttrAccess.execute(attributableValue.getAttributes());
189189
String valAttr = RRuntime.asStringLengthOne(valAttrObj);
190190
// GNUR uses == to compare strings here
191-
if (valAttr != null && valAttr != pckgAttr) {
191+
if (valAttr != null && !valAttr.equals(pckgAttr)) {
192192
return RNull.instance;
193193
}
194194
}

0 commit comments

Comments
 (0)