Skip to content

Commit

Permalink
[JVM] Fix all -Xlint:deprecation,unchecked warnings
Browse files Browse the repository at this point in the history
We should probably use `-Xlint:all` some day, but:

1. There are a lot more warnings to go.

2. This is supposed to be part of an atomics PR.

So just focus on the warnings that are visible by default for now. Lint
for these to prevent them from popping up again.
  • Loading branch information
Kaiepi committed Jul 27, 2022
1 parent 572d61d commit 7b79336
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 43 deletions.
6 changes: 3 additions & 3 deletions src/vm/jvm/runtime/org/raku/nqp/runtime/BootJavaInterop.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ protected SixModelObject computeInterop(ThreadContext tc, Class<?> klass) {

CompilationUnit adaptorUnit;
try {
adaptorUnit = (CompilationUnit) adaptor.constructed.newInstance();
} catch (ReflectiveOperationException roe) {
throw new RuntimeException(roe);
adaptorUnit = (CompilationUnit) adaptor.constructed.getDeclaredConstructor().newInstance();
} catch (ReflectiveOperationException e) {
throw ExceptionHandling.dieInternal(tc, e);
}
adaptorUnit.initializeCompilationUnit(tc);

Expand Down
12 changes: 9 additions & 3 deletions src/vm/jvm/runtime/org/raku/nqp/runtime/CompilationUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,15 @@ public static void enterFromMain(Class<?> cuType, int entryCodeRefIdx, String[]
*/
public static CompilationUnit setupCompilationUnit(ThreadContext tc, Class<?> cuType, boolean shared)
throws InstantiationException, IllegalAccessException {
CompilationUnit cu = (CompilationUnit)cuType.newInstance();
cu.shared = shared;
cu.initializeCompilationUnit(tc);
CompilationUnit cu = null;
try {
cu = (CompilationUnit)cuType.getDeclaredConstructor().newInstance();
cu.shared = shared;
cu.initializeCompilationUnit(tc);
}
catch (ReflectiveOperationException e) {
throw ExceptionHandling.dieInternal(tc, e);
}
return cu;
}

Expand Down
13 changes: 9 additions & 4 deletions src/vm/jvm/runtime/org/raku/nqp/runtime/LibraryLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,15 @@ public void load(ThreadContext tc, byte[] buffer) {
}

private static void loadClass(ThreadContext tc, Class<?> c) throws Throwable {
CompilationUnit cu = (CompilationUnit)c.newInstance();
cu.shared = tc.gc.sharingHint;
cu.initializeCompilationUnit(tc);
cu.runLoadIfAvailable(tc);
try {
CompilationUnit cu = (CompilationUnit)c.getDeclaredConstructor().newInstance();
cu.shared = tc.gc.sharingHint;
cu.initializeCompilationUnit(tc);
cu.runLoadIfAvailable(tc);
}
catch (ReflectiveOperationException e) {
throw ExceptionHandling.dieInternal(tc, e);
}
}

private static Class<?> loadJar(byte[] buffer) throws Exception {
Expand Down
6 changes: 4 additions & 2 deletions src/vm/jvm/runtime/org/raku/nqp/runtime/NativeCallOps.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static SixModelObject call(SixModelObject returns, SixModelObject callObj
CPPStructREPRData repr_data = (CPPStructREPRData)returns.st.REPRData;
Class<?> structClass = repr_data.structureClass;
cppstruct = (CPPStructInstance)returns.st.REPR.allocate(tc, returns.st);
cppstruct.storage = (Structure)structClass.newInstance();
cppstruct.storage = (Structure)structClass.getDeclaredConstructor().newInstance();
cArgs[i] = cppstruct.storage;
}
else {
Expand Down Expand Up @@ -188,7 +188,9 @@ public static SixModelObject call(SixModelObject returns, SixModelObject callObj
return toNQPType(tc, call.ret_type, returns, returned);
}
}
catch (ControlException e) { throw e; }
catch (ControlException e) {
throw ExceptionHandling.dieInternal(tc, e);
}
catch (Throwable t) {
throw ExceptionHandling.dieInternal(tc, t);
}
Expand Down
16 changes: 8 additions & 8 deletions src/vm/jvm/runtime/org/raku/nqp/runtime/Ops.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
Expand Down Expand Up @@ -3804,8 +3805,10 @@ public static SixModelObject iter(SixModelObject agg, ThreadContext tc) {
else if (agg.st.REPR instanceof VMHash) {
SixModelObject iterType = tc.curFrame.codeRef.staticInfo.compUnit.hllConfig.hashIteratorType;
VMIterInstance iter = (VMIterInstance)iterType.st.REPR.allocate(tc, iterType.st);
VMHashInstance hash = (VMHashInstance)agg;
Map<String, ?> storage = new HashMap< >(hash.storage);
iter.target = agg;
iter.hashKeyIter = ((HashMap)((VMHashInstance)agg).storage.clone()).keySet().iterator();
iter.hashKeyIter = storage.keySet().iterator();
iter.iterMode = VMIterInstance.MODE_HASH;
return iter;
}
Expand Down Expand Up @@ -7023,12 +7026,12 @@ public static long coerce_n2i(double in) {
return Long.MIN_VALUE;
}
else {
return new Double(in).longValue();
return Double.valueOf(in).longValue();
}
}

public static double coerce_i2n(long in) {
return new Long(in).doubleValue();
return Long.valueOf(in).doubleValue();
}

/* Long literal workaround. */
Expand Down Expand Up @@ -7387,7 +7390,7 @@ public static SixModelObject loadcompunit(SixModelObject obj, long compileeHLL,
try {
EvalResult res = (EvalResult)obj;
Class<?> cuClass = tc.gc.byteClassLoader.defineClass(res.jc.name, res.jc.bytes);
res.cu = (CompilationUnit) cuClass.newInstance();
res.cu = (CompilationUnit) cuClass.getDeclaredConstructor().newInstance();
if (compileeHLL != 0)
usecompileehllconfig(tc);
res.cu.initializeCompilationUnit(tc);
Expand All @@ -7396,11 +7399,8 @@ public static SixModelObject loadcompunit(SixModelObject obj, long compileeHLL,
res.jc = null;
return obj;
}
catch (ControlException e) {
throw e;
}
catch (Exception e) {
throw new RuntimeException(e);
throw ExceptionHandling.dieInternal(tc, e);
}
}
public static long iscompunit(SixModelObject obj, ThreadContext tc) {
Expand Down
7 changes: 3 additions & 4 deletions src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/CPPStruct.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ public SixModelObject allocate(ThreadContext tc, STable st) {
CPPStructREPRData repr_data = (CPPStructREPRData) st.REPRData;
obj.st = st;
try {
obj.storage = (Structure) repr_data.structureClass.newInstance();
obj.storage = (Structure) repr_data.structureClass.getDeclaredConstructor().newInstance();
}
catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
throw new RuntimeException(e);
catch (ReflectiveOperationException e) {
throw ExceptionHandling.dieInternal(tc, e);
}
return obj;
}
Expand Down
7 changes: 3 additions & 4 deletions src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/CStruct.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ public SixModelObject allocate(ThreadContext tc, STable st) {
CStructREPRData repr_data = (CStructREPRData) st.REPRData;
obj.st = st;
try {
obj.storage = (Structure) repr_data.structureClass.newInstance();
obj.storage = (Structure) repr_data.structureClass.getDeclaredConstructor().newInstance();
}
catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
throw new RuntimeException(e);
catch (ReflectiveOperationException e) {
throw ExceptionHandling.dieInternal(tc, e);
}
return obj;
}
Expand Down
7 changes: 3 additions & 4 deletions src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/CUnion.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,10 @@ public SixModelObject allocate(ThreadContext tc, STable st) {
CUnionREPRData repr_data = (CUnionREPRData) st.REPRData;
obj.st = st;
try {
obj.storage = (Union) repr_data.structureClass.newInstance();
obj.storage = (Union) repr_data.structureClass.getDeclaredConstructor().newInstance();
}
catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
throw new RuntimeException(e);
catch (ReflectiveOperationException e) {
throw ExceptionHandling.dieInternal(tc, e);
}
return obj;
}
Expand Down
11 changes: 7 additions & 4 deletions src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/P6Opaque.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,15 @@ private void installJVMType(ThreadContext tc, STable st, List<AttrInfo> attrInfo

((P6OpaqueREPRData)st.REPRData).jvmClass = use;
try {
((P6OpaqueREPRData)st.REPRData).instance = (P6OpaqueBaseInstance)((P6OpaqueREPRData)st.REPRData).jvmClass.newInstance();
((P6OpaqueREPRData)st.REPRData).instance =
(P6OpaqueBaseInstance)((P6OpaqueREPRData)st.REPRData).jvmClass.getDeclaredConstructor().newInstance();
}
catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
catch (ReflectiveOperationException e) {
throw ExceptionHandling.dieInternal(tc, e);
}
finally {
((P6OpaqueREPRData)st.REPRData).instance.st = st;
}
((P6OpaqueREPRData)st.REPRData).instance.st = st;
}

private Class<?> generateJVMClass(ThreadContext tc, List<AttrInfo> attrInfoList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ public SixModelObject cas_attribute_boxed(ThreadContext tc, SixModelObject class
catch (Exception e) {
throw ExceptionHandling.dieInternal(tc, e);
}
finally {
return result == null ? Ops.createNull(tc) : result;
}
return result == null ? Ops.createNull(tc) : result;
}

@Override
Expand Down Expand Up @@ -161,9 +159,7 @@ public SixModelObject atomic_load_attribute_boxed(ThreadContext tc, SixModelObje
catch (Exception e) {
throw ExceptionHandling.dieInternal(tc, e);
}
finally {
return result == null ? Ops.createNull(tc) : result;
}
return result == null ? Ops.createNull(tc) : result;
}

public SixModelObject posDelegate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public boolean boolify() {
public String key_s(ThreadContext tc) {
switch (iterMode) {
case MODE_ARRAY:
return new Long(idx).toString();
return Long.valueOf(idx).toString();
case MODE_HASH:
if (beforeStart || afterEnd)
throw ExceptionHandling.dieInternal(tc, "You have not advanced to the first item of the hash iterator, or have gone past the end");
Expand Down

0 comments on commit 7b79336

Please sign in to comment.