Skip to content

Commit df199cd

Browse files
committed
[GR-13337] Ensure spotbugs compliance.
PullRequest: truffleruby/604
2 parents f1c1e5f + 79b34c9 commit df199cd

File tree

10 files changed

+105
-102
lines changed

10 files changed

+105
-102
lines changed

doc/contributor/static-analysis.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ Passing CheckStyle is enforced in our CI gate.
3636
$ mx checkstyle
3737
```
3838

39-
### FindBugs
39+
### SpotBugs
4040

41-
[FindBugs](http://findbugs.sourceforge.net) looks for potential Java
42-
programming errors. We run it with the default Graal project configuration.
43-
Passing FindBugs is enforced in our CI gate.
41+
[SpotBugs](https://spotbugs.github.io) looks for potential Java programming
42+
errors. We run it with the default Graal project configuration. Passing
43+
SpotBugs is enforced in our CI gate.
4444

4545
```
46-
$ mx findbugs
46+
$ mx spotbugs
4747
```
4848

4949
## Ruby

mx.truffleruby/suite.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
suite = {
2-
"mxversion": "5.156.0",
2+
"mxversion": "5.210.3",
33
"name": "truffleruby",
44

55
"imports": {
@@ -9,7 +9,7 @@
99
"name": "tools",
1010
"subdir": True,
1111
# version must always be equal to the version of the "sulong" import below
12-
"version": "892e0854c0b1af7e29540eadb862f221d113aaf0",
12+
"version": "9be7ab457c51adf6d985ca578c60c450925be0ac",
1313
"urls": [
1414
{"url": "https://github.com/oracle/graal.git", "kind": "git"},
1515
{"url": "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind": "binary"},
@@ -19,7 +19,7 @@
1919
"name": "sulong",
2020
"subdir": True,
2121
# version must always be equal to the version of the "tools" import above
22-
"version": "892e0854c0b1af7e29540eadb862f221d113aaf0",
22+
"version": "9be7ab457c51adf6d985ca578c60c450925be0ac",
2323
"urls": [
2424
{"url": "https://github.com/oracle/graal.git", "kind": "git"},
2525
{"url": "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind": "binary"},

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@
8282
import java.io.File;
8383
import java.io.IOException;
8484
import java.nio.ByteBuffer;
85-
import java.nio.file.Path;
86-
import java.nio.file.Paths;
8785
import java.security.NoSuchAlgorithmException;
8886
import java.security.SecureRandom;
8987
import java.util.concurrent.locks.ReentrantLock;
@@ -756,8 +754,9 @@ private String searchRubyHome(Options options) throws IOException {
756754
// Use the path relative to the launcher
757755

758756
if (!options.LAUNCHER.isEmpty()) {
759-
final Path canonicalLauncherPath = Paths.get(new File(options.LAUNCHER).getCanonicalPath());
760-
final File candidate = canonicalLauncherPath.getParent().getParent().toFile();
757+
final File canonicalLauncherPath = new File(options.LAUNCHER).getCanonicalFile();
758+
final File launcherDir = canonicalLauncherPath.getParentFile();
759+
final File candidate = launcherDir == null ? null : launcherDir.getParentFile();
761760
RubyLanguage.LOGGER.config(() -> String.format("trying home %s guessed from executable %s, as the Ruby home", candidate, options.LAUNCHER));
762761
if (isRubyHome(candidate)) {
763762
return candidate.getCanonicalPath();
@@ -777,9 +776,8 @@ private String searchRubyHome(Options options) throws IOException {
777776
}
778777

779778
private boolean isRubyHome(File path) {
780-
return Paths.get(path.toString(), "lib", "truffle").toFile().isDirectory() &&
781-
Paths.get(path.toString(), "lib", "ruby").toFile().isDirectory() &&
782-
Paths.get(path.toString(), "lib", "patches").toFile().isDirectory();
779+
final File lib = new File(path, "lib");
780+
return new File(lib, "truffle").isDirectory() && new File(lib, "ruby").isDirectory() && new File(lib, "patches").isDirectory();
783781
}
784782

785783
public TruffleNFIPlatform getTruffleNFI() {

src/main/java/org/truffleruby/builtins/AmbiguousOptionalArgumentChecker.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.oracle.truffle.api.dsl.NodeFactory;
1414
import com.oracle.truffle.api.dsl.Specialization;
1515
import org.truffleruby.RubyLanguage;
16+
import org.truffleruby.SuppressFBWarnings;
1617
import org.truffleruby.language.RubyNode;
1718

1819
import java.lang.reflect.Method;
@@ -38,6 +39,7 @@ public static void verifyNoAmbiguousOptionalArguments(NodeFactory<? extends Ruby
3839
}
3940
}
4041

42+
@SuppressFBWarnings("Dm")
4143
private static void verifyNoAmbiguousOptionalArgumentsWithReflection(NodeFactory<? extends RubyNode> nodeFactory, CoreMethod methodAnnotation) {
4244
if (methodAnnotation.optional() > 0 || methodAnnotation.needsBlock()) {
4345
final int opt = methodAnnotation.optional();
@@ -121,8 +123,14 @@ private static boolean isParameterUnguarded(Method method, Parameter[] parameter
121123

122124
private static List<Method> specializations(Class<?> node) {
123125
Method[] methods = node.getDeclaredMethods();
124-
return Arrays.stream(methods).filter(m -> m.isAnnotationPresent(Specialization.class)).collect(Collectors.toList());
126+
return Arrays.stream(methods).filter(m -> isSpecialization(m)).collect(Collectors.toList());
125127
}
128+
129+
@SuppressFBWarnings("Dm")
130+
private static boolean isSpecialization(Method m) {
131+
return m.isAnnotationPresent(Specialization.class);
132+
}
133+
126134
private static boolean isGuarded(String name, String[] guards) {
127135
for (String guard : guards) {
128136
if (guard.equals("wasProvided(" + name + ")") ||

src/main/java/org/truffleruby/builtins/LowerFixnumChecker.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.oracle.truffle.api.dsl.Specialization;
1515
import com.oracle.truffle.api.frame.VirtualFrame;
1616
import org.truffleruby.RubyLanguage;
17+
import org.truffleruby.SuppressFBWarnings;
1718
import org.truffleruby.core.array.ArrayUtils;
1819
import org.truffleruby.language.RubyNode;
1920

@@ -24,6 +25,7 @@ public class LowerFixnumChecker {
2425

2526
public static boolean SUCCESS = true;
2627

28+
@SuppressFBWarnings("Dm")
2729
public static void checkLowerFixnumArguments(NodeFactory<? extends RubyNode> nodeFactory, int initialSkip, int[] lowerFixnum) {
2830
final Class<? extends RubyNode> nodeClass = nodeFactory.getNodeClass();
2931
byte[] lowerArgs = null;

src/main/java/org/truffleruby/gem/bcrypt/BCrypt.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ private static String encode_base64(byte d[], int len)
423423
* @return the decoded value of x
424424
*/
425425
private static byte char64(char x) {
426-
if (x < 0 || x > index_64.length) {
426+
if (x >= index_64.length) {
427427
return -1;
428428
}
429429
return index_64[x];

src/main/java/org/truffleruby/language/loader/FileLoader.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ public FileLoader(RubyContext context) {
3838
}
3939

4040
public void ensureReadable(String path) {
41-
if (context == null) {
42-
// Ignore during pre-initialisation
43-
return;
44-
}
45-
4641
final File file = new File(path);
4742

4843
if (!file.exists()) {
@@ -63,7 +58,7 @@ public RubySource loadFile(String path) throws IOException {
6358

6459
final String name;
6560

66-
if (context != null && context.isPreInitializing()) {
61+
if (context.isPreInitializing()) {
6762
name = RubyLanguage.RUBY_HOME_SCHEME + Paths.get(context.getRubyHome()).relativize(Paths.get(path));
6863
} else {
6964
name = path;

0 commit comments

Comments
 (0)