Skip to content

Commit 3f9ada8

Browse files
committed
[GR-14972] Fix most Sonarqube-reported issues
PullRequest: graalpython/475
2 parents 975f6c0 + 5652733 commit 3f9ada8

33 files changed

+110
-74
lines changed

ci.jsonnet

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@
128128

129129
local labsjdk8Mixin = {
130130
downloads +: {
131-
JAVA_HOME: utils.download("labsjdk", "8u202-jvmci-0.57"),
132-
EXTRA_JAVA_HOMES : { pathlist: [utils.download("oraclejdk", "11+20")] },
131+
JAVA_HOME: utils.download("labsjdk", "8u202-jvmci-0.58"),
132+
EXTRA_JAVA_HOMES : { pathlist: [utils.download("oraclejdk", "11+28")] },
133133
},
134134
environment +: {
135135
CI: "true",

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonCompiler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2019, 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
@@ -64,6 +64,7 @@ protected void exec(List<String> args) {
6464
System.exit(status);
6565
}
6666
} catch (IOException | InterruptedException e) {
67+
Thread.currentThread().interrupt();
6768
throw new RuntimeException(e);
6869
}
6970
}

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonLD.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ void addFile(String f) {
176176
}
177177
nmProc.waitFor();
178178
} catch (InterruptedException | IOException e) {
179+
Thread.currentThread().interrupt();
179180
throw new RuntimeException(e);
180181
}
181182
}
@@ -196,6 +197,7 @@ private List<String> searchLib(List<String> libraryDirs, String lib) {
196197
try {
197198
bcFiles.addAll(arMembers(pathString));
198199
} catch (IOException | InterruptedException e) {
200+
Thread.currentThread().interrupt();
199201
throw new RuntimeException(e);
200202
}
201203
} else {
@@ -212,24 +214,21 @@ private List<String> searchLib(List<String> libraryDirs, String lib) {
212214

213215
private Collection<? extends String> arMembers(String path) throws IOException, InterruptedException {
214216
List<String> members = new ArrayList<>();
215-
File temp = File.createTempFile(path, Long.toString(System.nanoTime()));
216-
temp.delete();
217-
temp.mkdir();
218-
temp.deleteOnExit();
217+
Path temp = Files.createTempDirectory(Long.toString(System.nanoTime()));
219218

220219
ProcessBuilder extractAr = new ProcessBuilder();
221220
extractAr.redirectInput(Redirect.INHERIT);
222221
extractAr.redirectError(Redirect.INHERIT);
223222
extractAr.redirectOutput(Redirect.PIPE);
224-
extractAr.directory(temp);
223+
extractAr.directory(temp.toFile());
225224
logV("ar", path);
226225
// "ar t" lists the members one per line
227226
extractAr.command("ar", "t", path);
228227
Process start = extractAr.start();
229228
try (BufferedReader buffer = new BufferedReader(new InputStreamReader(start.getInputStream()))) {
230229
String line = null;
231230
while ((line = buffer.readLine()) != null) {
232-
members.add(temp.getAbsolutePath() + File.separator + line);
231+
members.add(temp.toFile().getAbsolutePath() + File.separator + line);
233232
}
234233
}
235234
start.waitFor();

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ private static void subExec(List<String> args, List<String> subProcessDefs) {
715715
try {
716716
System.exit(new ProcessBuilder(cmd.toArray(new String[0])).inheritIO().start().waitFor());
717717
} catch (IOException | InterruptedException e) {
718+
Thread.currentThread().interrupt();
718719
System.err.println(e.getMessage());
719720
System.exit(-1);
720721
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {
115115
public static final String MIME_TYPE = "text/x-python";
116116
public static final String EXTENSION = ".py";
117117

118-
public Assumption singleContextAssumption = Truffle.getRuntime().createAssumption("Only a single context is active");
118+
public final Assumption singleContextAssumption = Truffle.getRuntime().createAssumption("Only a single context is active");
119119

120120
private final NodeFactory nodeFactory;
121121
public final ConcurrentHashMap<Class<? extends PythonBuiltinBaseNode>, RootCallTarget> builtinCallTargetCache = new ConcurrentHashMap<>();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public String doD(double x) {
282282
@TruffleBoundary
283283
public String doPI(PInt x) {
284284
BigInteger value = x.getValue();
285-
return buildString(value.compareTo(BigInteger.ZERO) == -1, value.abs().toString(2));
285+
return buildString(value.compareTo(BigInteger.ZERO) < 0, value.abs().toString(2));
286286
}
287287

288288
@Specialization
@@ -336,7 +336,7 @@ public String doD(double x) {
336336
@TruffleBoundary
337337
public String doPI(PInt x) {
338338
BigInteger value = x.getValue();
339-
return buildString(value.compareTo(BigInteger.ZERO) == -1, value.abs().toString(8));
339+
return buildString(value.compareTo(BigInteger.ZERO) < 0, value.abs().toString(8));
340340
}
341341

342342
@Specialization
@@ -390,7 +390,7 @@ public String doD(double x) {
390390
@TruffleBoundary
391391
public String doPI(PInt x) {
392392
BigInteger value = x.getValue();
393-
return buildString(value.compareTo(BigInteger.ZERO) == -1, value.abs().toString(8));
393+
return buildString(value.compareTo(BigInteger.ZERO) < 0, value.abs().toString(8));
394394
}
395395

396396
@Specialization

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ private int readInt() {
512512
int ch2 = readByte() & 0xFF;
513513
int ch3 = readByte() & 0xFF;
514514
int ch4 = readByte() & 0xFF;
515-
return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
515+
return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + ch4);
516516
}
517517

518518
private long read_long64() { // cpython calls this r_long64

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ protected static BigDecimal sqrtBigNumber(BigInteger value) {
174174
@Override
175175
public double doPI(PInt value) {
176176
BigInteger bValue = value.getValue();
177-
checkMathDomainError(bValue.compareTo(BigInteger.ZERO) == -1);
177+
checkMathDomainError(bValue.compareTo(BigInteger.ZERO) < 0);
178178
return sqrtBigNumber(bValue).doubleValue();
179179
}
180180

@@ -1252,7 +1252,7 @@ public abstract static class AcoshNode extends MathDoubleUnaryBuiltinNode {
12521252
@Override
12531253
public double doPI(PInt value) {
12541254
BigInteger bValue = value.getValue();
1255-
checkMathDomainError(bValue.compareTo(BigInteger.ONE) == -1);
1255+
checkMathDomainError(bValue.compareTo(BigInteger.ONE) < 0);
12561256

12571257
BigDecimal sqrt = SqrtNode.sqrtBigNumber(bValue.multiply(bValue).subtract(BigInteger.ONE));
12581258
BigDecimal bd = new BigDecimal(bValue);
@@ -1526,7 +1526,7 @@ public double logDN(double value, @SuppressWarnings("unused") PNone novalue,
15261526
public double logPIN(PInt value, @SuppressWarnings("unused") PNone novalue,
15271527
@Cached("createBinaryProfile()") ConditionProfile doNotFit) {
15281528
BigInteger bValue = value.getValue();
1529-
raiseMathError(doNotFit, bValue.compareTo(BigInteger.ZERO) == -1);
1529+
raiseMathError(doNotFit, bValue.compareTo(BigInteger.ZERO) < 0);
15301530
return logBigInteger(bValue);
15311531
}
15321532

@@ -1584,7 +1584,7 @@ public double logPID(PInt value, double base,
15841584
@Cached("createBinaryProfile()") ConditionProfile doNotFit,
15851585
@Cached("createBinaryProfile()") ConditionProfile divByZero) {
15861586
BigInteger bValue = value.getValue();
1587-
raiseMathError(doNotFit, bValue.compareTo(BigInteger.ZERO) == -1 || base <= 0);
1587+
raiseMathError(doNotFit, bValue.compareTo(BigInteger.ZERO) < 0 || base <= 0);
15881588
double logBase = countBase(base, divByZero);
15891589
return logBigInteger(bValue) / logBase;
15901590
}
@@ -1607,7 +1607,7 @@ public double logPIPI(PInt value, PInt base,
16071607
@Cached("createBinaryProfile()") ConditionProfile divByZero) {
16081608
BigInteger bValue = value.getValue();
16091609
BigInteger bBase = base.getValue();
1610-
raiseMathError(doNotFit, bValue.compareTo(BigInteger.ZERO) == -1 || bBase.compareTo(BigInteger.ZERO) <= 0);
1610+
raiseMathError(doNotFit, bValue.compareTo(BigInteger.ZERO) < 0 || bBase.compareTo(BigInteger.ZERO) <= 0);
16111611
double logBase = countBase(bBase, divByZero);
16121612
return logBigInteger(bValue) / logBase;
16131613
}
@@ -2230,6 +2230,7 @@ static double lanczos_sum(double x) {
22302230
den = den / x + LANCZOS_DEN_COEFFS[i];
22312231
}
22322232
}
2233+
assert den > 0.0 : "den cannot be zero, because LANCZOS_DEN_COEFFS are added";
22332234
return num / den;
22342235
}
22352236

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ReadlineModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private static final class LocalData {
8383
private final HashMap<String, String> bindings = new HashMap<>();
8484
private final List<String> history = new ArrayList<>();
8585
protected Object completer = null;
86-
public boolean autoHistory = true;
86+
protected boolean autoHistory = true;
8787
protected String completerDelims = null;
8888
}
8989

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SignalModuleBuiltins.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public void postInitialize(PythonCore core) {
114114
poll = signalQueue.poll();
115115
}
116116
} catch (InterruptedException e) {
117+
Thread.currentThread().interrupt();
117118
}
118119
return poll;
119120
});
@@ -306,18 +307,29 @@ final class Signals {
306307
}
307308
}
308309

309-
@TruffleBoundary
310-
synchronized static void scheduleAlarm(long seconds) {
311-
new Thread(() -> {
310+
private static class Alarm implements Runnable {
311+
private final long seconds;
312+
313+
Alarm(long seconds) {
314+
this.seconds = seconds;
315+
}
316+
317+
public void run() {
312318
long t0 = System.currentTimeMillis();
313319
while ((System.currentTimeMillis() - t0) < seconds * 1000) {
314320
try {
315321
Thread.sleep(seconds * 1000);
316322
} catch (InterruptedException e) {
323+
Thread.currentThread().interrupt();
317324
}
318325
}
319326
sun.misc.Signal.raise(new sun.misc.Signal("ALRM"));
320-
}).start();
327+
}
328+
}
329+
330+
@TruffleBoundary
331+
synchronized static void scheduleAlarm(long seconds) {
332+
new Thread(new Alarm(seconds)).start();
321333
}
322334

323335
private static class PythonSignalHandler implements sun.misc.SignalHandler {

0 commit comments

Comments
 (0)