1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-25 22:53:22 +00:00

Fix a couple of warnings

This commit is contained in:
Jonathan Coates 2024-03-10 12:04:40 +00:00
parent 3b8813cf8f
commit eead67e314
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
7 changed files with 32 additions and 23 deletions

View File

@ -116,6 +116,7 @@ public static MethodResult pullEventRaw(@Nullable String filter, ILuaCallback ca
* @return The method result which represents this yield.
* @see #pullEvent(String, ILuaCallback)
*/
@SuppressWarnings("NamedLikeContextualKeyword")
public static MethodResult yield(@Nullable Object[] arguments, ILuaCallback callback) {
Objects.requireNonNull(callback, "callback cannot be null");
return new MethodResult(arguments, callback);

View File

@ -4,6 +4,7 @@
package dan200.computercraft.core.apis.http.options;
import com.google.errorprone.annotations.Immutable;
/**
* Options for a given HTTP request or websocket, which control its resource constraints.
@ -14,5 +15,6 @@
* @param websocketMessage The maximum size of a websocket message (outgoing and incoming).
* @param useProxy Whether to use the configured proxy.
*/
@Immutable
public record Options(Action action, long maxUpload, long maxDownload, int websocketMessage, boolean useProxy) {
}

View File

@ -4,6 +4,7 @@
package dan200.computercraft.core.apis.http.options;
import com.google.errorprone.annotations.Immutable;
import com.google.errorprone.annotations.concurrent.LazyInit;
import javax.annotation.Nullable;
@ -11,6 +12,7 @@
import java.util.OptionalInt;
import java.util.OptionalLong;
@Immutable
public final class PartialOptions {
public static final PartialOptions DEFAULT = new PartialOptions(
null, OptionalLong.empty(), OptionalLong.empty(), OptionalInt.empty(), Optional.empty()

View File

@ -27,7 +27,7 @@ static RuntimeException throwUnchecked(Throwable t) {
return throwUnchecked0(t);
}
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "TypeParameterUnusedInFormals" })
private static <T extends Throwable> T throwUnchecked0(Throwable t) throws T {
throw (T) t;
}

View File

@ -46,24 +46,9 @@ class LuaCoverage {
}
void write(Writer out) throws IOException {
Files.find(ROOT, Integer.MAX_VALUE, (path, attr) -> attr.isRegularFile()).forEach(path -> {
var relative = ROOT.relativize(path);
var full = relative.toString().replace('\\', '/');
if (!full.endsWith(".lua")) return;
var possiblePaths = coverage.remove("/" + full);
if (possiblePaths == null) possiblePaths = coverage.remove(full);
if (possiblePaths == null) {
possiblePaths = Int2IntMaps.EMPTY_MAP;
LOG.warn("{} has no coverage data", full);
}
try {
writeCoverageFor(out, path, possiblePaths);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
try (var files = Files.find(ROOT, Integer.MAX_VALUE, (path, attr) -> attr.isRegularFile())) {
files.forEach(path -> writeSingleFile(out, path));
}
for (var filename : coverage.keySet()) {
if (filename.startsWith("/test-rom/")) continue;
@ -71,6 +56,25 @@ void write(Writer out) throws IOException {
}
}
private void writeSingleFile(Writer out, Path path) {
var relative = ROOT.relativize(path);
var full = relative.toString().replace('\\', '/');
if (!full.endsWith(".lua")) return;
var possiblePaths = coverage.remove("/" + full);
if (possiblePaths == null) possiblePaths = coverage.remove(full);
if (possiblePaths == null) {
possiblePaths = Int2IntMaps.EMPTY_MAP;
LOG.warn("{} has no coverage data", full);
}
try {
writeCoverageFor(out, path, possiblePaths);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
private void writeCoverageFor(Writer out, Path fullName, Map<Integer, Integer> visitedLines) throws IOException {
if (!Files.exists(fullName)) {
LOG.error("Cannot locate file {}", fullName);

View File

@ -101,7 +101,7 @@ public static void run(WritableMount mount, Consumer<Computer> setup, int maxTic
try {
context.ensureClosed(1, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new IllegalStateException("Runtime thread was interrupted", e);
Thread.currentThread().interrupt();
}
}
}

View File

@ -65,7 +65,7 @@ public void startAndWait(Worker worker) throws Exception {
} finally {
errorLock.unlock();
}
} while (worker.executed == 0 || thread.hasPendingWork());
} while (!worker.executed || thread.hasPendingWork());
}
@GuardedBy("errorLock")
@ -87,7 +87,7 @@ public final class Worker implements ComputerScheduler.Worker, MetricsObserver {
private final Task run;
private final ComputerScheduler.Executor executor;
private long[] totals = new long[16];
volatile int executed = 0;
private volatile boolean executed = false;
private Worker(ComputerScheduler scheduler, Task run) {
this.run = run;
@ -102,7 +102,7 @@ public ComputerScheduler.Executor executor() {
public void work() {
try {
run.run(executor);
executed++;
executed = true;
} catch (Throwable e) {
errorLock.lock();
try {