1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-09-28 15:08:47 +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 final class MethodResult {
* @return The method result which represents this yield. * @return The method result which represents this yield.
* @see #pullEvent(String, ILuaCallback) * @see #pullEvent(String, ILuaCallback)
*/ */
@SuppressWarnings("NamedLikeContextualKeyword")
public static MethodResult yield(@Nullable Object[] arguments, ILuaCallback callback) { public static MethodResult yield(@Nullable Object[] arguments, ILuaCallback callback) {
Objects.requireNonNull(callback, "callback cannot be null"); Objects.requireNonNull(callback, "callback cannot be null");
return new MethodResult(arguments, callback); return new MethodResult(arguments, callback);

View File

@ -4,6 +4,7 @@
package dan200.computercraft.core.apis.http.options; 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. * Options for a given HTTP request or websocket, which control its resource constraints.
@ -14,5 +15,6 @@ package dan200.computercraft.core.apis.http.options;
* @param websocketMessage The maximum size of a websocket message (outgoing and incoming). * @param websocketMessage The maximum size of a websocket message (outgoing and incoming).
* @param useProxy Whether to use the configured proxy. * @param useProxy Whether to use the configured proxy.
*/ */
@Immutable
public record Options(Action action, long maxUpload, long maxDownload, int websocketMessage, boolean useProxy) { 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; package dan200.computercraft.core.apis.http.options;
import com.google.errorprone.annotations.Immutable;
import com.google.errorprone.annotations.concurrent.LazyInit; import com.google.errorprone.annotations.concurrent.LazyInit;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -11,6 +12,7 @@ import java.util.Optional;
import java.util.OptionalInt; import java.util.OptionalInt;
import java.util.OptionalLong; import java.util.OptionalLong;
@Immutable
public final class PartialOptions { public final class PartialOptions {
public static final PartialOptions DEFAULT = new PartialOptions( public static final PartialOptions DEFAULT = new PartialOptions(
null, OptionalLong.empty(), OptionalLong.empty(), OptionalInt.empty(), Optional.empty() null, OptionalLong.empty(), OptionalLong.empty(), OptionalInt.empty(), Optional.empty()

View File

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

View File

@ -46,24 +46,9 @@ class LuaCoverage {
} }
void write(Writer out) throws IOException { void write(Writer out) throws IOException {
Files.find(ROOT, Integer.MAX_VALUE, (path, attr) -> attr.isRegularFile()).forEach(path -> { try (var files = Files.find(ROOT, Integer.MAX_VALUE, (path, attr) -> attr.isRegularFile())) {
var relative = ROOT.relativize(path); files.forEach(path -> writeSingleFile(out, 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);
}
});
for (var filename : coverage.keySet()) { for (var filename : coverage.keySet()) {
if (filename.startsWith("/test-rom/")) continue; if (filename.startsWith("/test-rom/")) continue;
@ -71,6 +56,25 @@ class LuaCoverage {
} }
} }
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 { private void writeCoverageFor(Writer out, Path fullName, Map<Integer, Integer> visitedLines) throws IOException {
if (!Files.exists(fullName)) { if (!Files.exists(fullName)) {
LOG.error("Cannot locate file {}", fullName); LOG.error("Cannot locate file {}", fullName);

View File

@ -101,7 +101,7 @@ public class ComputerBootstrap {
try { try {
context.ensureClosed(1, TimeUnit.SECONDS); context.ensureClosed(1, TimeUnit.SECONDS);
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new IllegalStateException("Runtime thread was interrupted", e); Thread.currentThread().interrupt();
} }
} }
} }

View File

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