Skip to content

Commit

Permalink
Enable default Error Prone checks
Browse files Browse the repository at this point in the history
  • Loading branch information
electrum committed Aug 26, 2024
1 parent 04c6995 commit 818ed07
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 33 deletions.
3 changes: 2 additions & 1 deletion aot/src/main/java/com/dylibso/chicory/aot/AotMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static java.lang.invoke.MethodHandles.insertArguments;
import static java.lang.invoke.MethodHandles.publicLookup;
import static java.lang.invoke.MethodType.methodType;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toSet;
Expand Down Expand Up @@ -506,7 +507,7 @@ private Class<?> loadClass(String className, byte[] classBytes) {
// run ASM verifier to help with debugging
try {
ClassReader reader = new ClassReader(classBytes);
CheckClassAdapter.verify(reader, true, new PrintWriter(System.out));
CheckClassAdapter.verify(reader, true, new PrintWriter(System.out, false, UTF_8));
} catch (NoClassDefFoundError ignored) {
// the ASM verifier is an optional dependency
} catch (Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class HostFunctionInvoker {
HostFunctionInvoker.class.getMethod(
"invoke", Instance.class, int.class, Value[].class));
} catch (NoSuchMethodException | IllegalAccessException e) {
throw new AssertionError(e);
throw new LinkageError(e.getMessage(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class ValueWrapper {
try {
HANDLE = lookup().unreflect(ValueWrapper.class.getMethod("wrap", Value.class));
} catch (NoSuchMethodException | IllegalAccessException e) {
throw new AssertionError(e);
throw new LinkageError(e.getMessage(), e);
}
}

Expand Down
10 changes: 9 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,19 @@
<configuration>
<release>${maven.compiler.release}</release>
<parameters>true</parameters>
<failOnWarning>true</failOnWarning>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<compilerArgs>
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne \
-XepDisableAllChecks \
-Xep:MissingCasesInEnumSwitch:OFF \
-Xep:MissingOverride:ERROR \
-Xep:MissingSummary:OFF \
-Xep:NonOverridingEquals:OFF \
-Xep:OperatorPrecedence:OFF \
-Xep:ReferenceEquality:OFF \
-Xep:UnnecessaryParentheses:OFF \
-XepExcludedPaths:.*/target/generated-(|test-)sources/.*</arg>
</compilerArgs>
<annotationProcessorPaths>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ static void eval(MStack stack, Instance instance, Deque<StackFrame> callStack)
SELECT(stack);
break;
case SELECT_T:
SELECT_T(stack, operands);
SELECT_T(stack);
break;
case LOCAL_GET:
stack.push(frame.local((int) operands[0]));
Expand Down Expand Up @@ -1819,7 +1819,7 @@ private static void SELECT(MStack stack) {
}
}

private static void SELECT_T(MStack stack, long[] operands) {
private static void SELECT_T(MStack stack) {
var pred = stack.pop().asInt();
var b = stack.pop();
var a = stack.pop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ public void fill(byte value) {
fill(value, 0, buffer.capacity());
}

@SuppressWarnings("ByteBufferBackingArray")
public void fill(byte value, int fromIndex, int toIndex) {
try {
// see https://appsintheopen.com/posts/53-resetting-bytebuffers-to-zero-in-java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,11 @@
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.maven.plugin.logging.Log;

public class JavaTestGen {

private static final String TEST_MODULE_NAME = "testModule";

private final Log log;

private final File baseDir;

private final File sourceTargetFolder;
Expand All @@ -57,15 +54,13 @@ public class JavaTestGen {
private final List<String> excludedUnlinkableWasts;

public JavaTestGen(
Log log,
File baseDir,
File sourceTargetFolder,
List<String> excludedTests,
List<String> excludedMalformedWasts,
List<String> excludedInvalidWasts,
List<String> excludedUninstantiableWasts,
List<String> excludedUnlinkableWasts) {
this.log = log;
this.baseDir = baseDir;
this.sourceTargetFolder = sourceTargetFolder;
this.excludedTests = excludedTests;
Expand Down Expand Up @@ -171,7 +166,6 @@ public CompilationUnit generate(
new AssignExpr(
new NameExpr(lastInstanceVarName),
generateModuleInstantiation(
cmd,
currentWasmFile,
importsName,
hostFuncs,
Expand Down Expand Up @@ -399,11 +393,7 @@ private List<Expression> generateInvoke(String varName, Command cmd) {
private static final String INDENT = TAB + TAB + TAB + TAB + TAB;

private static NameExpr generateModuleInstantiation(
Command cmd,
String wasmFile,
String importsName,
String hostFuncs,
boolean excludeInvalid) {
String wasmFile, String importsName, String hostFuncs, boolean excludeInvalid) {
return new NameExpr(
"TestModule.of(\n"
+ INDENT
Expand Down Expand Up @@ -478,7 +468,7 @@ private void generateAssertThrows(
+ exceptionType
+ ".class, () -> "
+ generateModuleInstantiation(
cmd, wasmFile, importsName, hostFuncs, false)
wasmFile, importsName, hostFuncs, false)
+ ")");

method.getBody().get().addStatement(assertThrows);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static String capitalize(String in) {
if (in.isEmpty()) {
return in;
}
return in.substring(0, 1).toUpperCase() + in.substring(1);
return Character.toUpperCase(in.charAt(0)) + in.substring(1);
}

public static String escapedCamelCase(String in) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ public void execute() throws MojoExecutionException {
var testSuiteDownloader = new TestSuiteDownloader(log);
var testGen =
new JavaTestGen(
log,
project.getBasedir(),
sourceDestinationFolder,
excludedTests,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,8 @@ public String text() {
public String moduleType() {
return moduleType;
}

public String as() {
return as;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static String capitalize(String in) {
if (in.isEmpty()) {
return in;
}
return in.substring(0, 1).toUpperCase() + in.substring(1);
return Character.toUpperCase(in.charAt(0)) + in.substring(1);
}

public static String escapedCamelCase(String in) {
Expand Down
7 changes: 6 additions & 1 deletion wasi/src/main/java/com/dylibso/chicory/wasi/WasiErrno.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,10 @@ enum WasiErrno {
ETIMEDOUT,
ETXTBSY,
EXDEV,
ENOTCAPABLE,
ENOTCAPABLE;

@SuppressWarnings("EnumOrdinal")
public int value() {
return ordinal();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ enum WasiFileType {
REGULAR_FILE,
SOCKET_DGRAM,
SOCKET_STREAM,
SYMBOLIC_LINK,
SYMBOLIC_LINK;

@SuppressWarnings("EnumOrdinal")
public int value() {
return ordinal();
}
}
8 changes: 4 additions & 4 deletions wasi/src/main/java/com/dylibso/chicory/wasi/WasiPreview1.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ public HostFunction fdFdstatGet() {

Memory memory = instance.memory();
memory.write(buf, new byte[8]);
memory.writeByte(buf, (byte) fileType.ordinal());
memory.writeByte(buf, (byte) fileType.value());
memory.writeShort(buf + 2, (short) flags);
memory.writeLong(buf + 8, rightsBase);
memory.writeLong(buf + 16, rightsInheriting);
Expand Down Expand Up @@ -758,7 +758,7 @@ public HostFunction fdReaddir() {
entry.putLong(0, cookie);
entry.putLong(8, ((Number) attributes.get("ino")).longValue());
entry.putInt(16, name.length);
entry.put(20, (byte) getFileType(attributes).ordinal());
entry.put(20, (byte) getFileType(attributes).value());
entry.position(24);
entry.put(name);

Expand Down Expand Up @@ -1610,7 +1610,7 @@ private Value[] wasiResult(WasiErrno errno) {
if (errno != WasiErrno.ESUCCESS) {
logger.info("result = " + errno.name());
}
return new Value[] {Value.i32(errno.ordinal())};
return new Value[] {Value.i32(errno.value())};
}

private static Path resolvePath(Path directory, String rawPathString) {
Expand Down Expand Up @@ -1638,7 +1638,7 @@ private static void writeFileStat(
memory.writeLong(buf, (long) attributes.get("dev"));
memory.writeLong(buf + 8, ((Number) attributes.get("ino")).longValue());
memory.write(buf + 16, new byte[8]);
memory.writeByte(buf + 16, (byte) fileType.ordinal());
memory.writeByte(buf + 16, (byte) fileType.value());
memory.writeLong(buf + 24, ((Number) attributes.get("nlink")).longValue());
memory.writeLong(buf + 32, (long) attributes.get("size"));
memory.writeLong(buf + 40, fileTimeToNanos(attributes, "lastAccessTime"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ public enum ExternalType {

private final int id;

@SuppressWarnings("EnumOrdinal")
ExternalType(int id) {
this.id = id;
assert ordinal() == id;
}

/**
Expand All @@ -33,11 +35,6 @@ public int id() {

private static final List<ExternalType> values = List.of(values());

static {
// integrity verification
assert values.stream().allMatch(e -> e.ordinal() == e.id());
}

public static ExternalType byId(int id) {
return values.get(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public final boolean equals(Object v) {
return false;
}
Value other = (Value) v;
return Objects.equals(type.id(), other.type.id()) && data == other.data;
return type.id() == other.type.id() && data == other.data;
}

@Override
Expand Down

0 comments on commit 818ed07

Please sign in to comment.