Skip to content

Commit 7b79336

Browse files
committed
[JVM] Fix all -Xlint:deprecation,unchecked warnings
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.
1 parent 572d61d commit 7b79336

File tree

11 files changed

+52
-43
lines changed

11 files changed

+52
-43
lines changed

src/vm/jvm/runtime/org/raku/nqp/runtime/BootJavaInterop.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ protected SixModelObject computeInterop(ThreadContext tc, Class<?> klass) {
232232

233233
CompilationUnit adaptorUnit;
234234
try {
235-
adaptorUnit = (CompilationUnit) adaptor.constructed.newInstance();
236-
} catch (ReflectiveOperationException roe) {
237-
throw new RuntimeException(roe);
235+
adaptorUnit = (CompilationUnit) adaptor.constructed.getDeclaredConstructor().newInstance();
236+
} catch (ReflectiveOperationException e) {
237+
throw ExceptionHandling.dieInternal(tc, e);
238238
}
239239
adaptorUnit.initializeCompilationUnit(tc);
240240

src/vm/jvm/runtime/org/raku/nqp/runtime/CompilationUnit.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,15 @@ public static void enterFromMain(Class<?> cuType, int entryCodeRefIdx, String[]
6363
*/
6464
public static CompilationUnit setupCompilationUnit(ThreadContext tc, Class<?> cuType, boolean shared)
6565
throws InstantiationException, IllegalAccessException {
66-
CompilationUnit cu = (CompilationUnit)cuType.newInstance();
67-
cu.shared = shared;
68-
cu.initializeCompilationUnit(tc);
66+
CompilationUnit cu = null;
67+
try {
68+
cu = (CompilationUnit)cuType.getDeclaredConstructor().newInstance();
69+
cu.shared = shared;
70+
cu.initializeCompilationUnit(tc);
71+
}
72+
catch (ReflectiveOperationException e) {
73+
throw ExceptionHandling.dieInternal(tc, e);
74+
}
6975
return cu;
7076
}
7177

src/vm/jvm/runtime/org/raku/nqp/runtime/LibraryLoader.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,15 @@ public void load(ThreadContext tc, byte[] buffer) {
6666
}
6767

6868
private static void loadClass(ThreadContext tc, Class<?> c) throws Throwable {
69-
CompilationUnit cu = (CompilationUnit)c.newInstance();
70-
cu.shared = tc.gc.sharingHint;
71-
cu.initializeCompilationUnit(tc);
72-
cu.runLoadIfAvailable(tc);
69+
try {
70+
CompilationUnit cu = (CompilationUnit)c.getDeclaredConstructor().newInstance();
71+
cu.shared = tc.gc.sharingHint;
72+
cu.initializeCompilationUnit(tc);
73+
cu.runLoadIfAvailable(tc);
74+
}
75+
catch (ReflectiveOperationException e) {
76+
throw ExceptionHandling.dieInternal(tc, e);
77+
}
7378
}
7479

7580
private static Class<?> loadJar(byte[] buffer) throws Exception {

src/vm/jvm/runtime/org/raku/nqp/runtime/NativeCallOps.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public static SixModelObject call(SixModelObject returns, SixModelObject callObj
115115
CPPStructREPRData repr_data = (CPPStructREPRData)returns.st.REPRData;
116116
Class<?> structClass = repr_data.structureClass;
117117
cppstruct = (CPPStructInstance)returns.st.REPR.allocate(tc, returns.st);
118-
cppstruct.storage = (Structure)structClass.newInstance();
118+
cppstruct.storage = (Structure)structClass.getDeclaredConstructor().newInstance();
119119
cArgs[i] = cppstruct.storage;
120120
}
121121
else {
@@ -188,7 +188,9 @@ public static SixModelObject call(SixModelObject returns, SixModelObject callObj
188188
return toNQPType(tc, call.ret_type, returns, returned);
189189
}
190190
}
191-
catch (ControlException e) { throw e; }
191+
catch (ControlException e) {
192+
throw ExceptionHandling.dieInternal(tc, e);
193+
}
192194
catch (Throwable t) {
193195
throw ExceptionHandling.dieInternal(tc, t);
194196
}

src/vm/jvm/runtime/org/raku/nqp/runtime/Ops.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import java.util.Collections;
5757
import java.util.EnumSet;
5858
import java.util.HashMap;
59+
import java.util.Iterator;
5960
import java.util.List;
6061
import java.util.Map;
6162
import java.util.Properties;
@@ -3804,8 +3805,10 @@ public static SixModelObject iter(SixModelObject agg, ThreadContext tc) {
38043805
else if (agg.st.REPR instanceof VMHash) {
38053806
SixModelObject iterType = tc.curFrame.codeRef.staticInfo.compUnit.hllConfig.hashIteratorType;
38063807
VMIterInstance iter = (VMIterInstance)iterType.st.REPR.allocate(tc, iterType.st);
3808+
VMHashInstance hash = (VMHashInstance)agg;
3809+
Map<String, ?> storage = new HashMap< >(hash.storage);
38073810
iter.target = agg;
3808-
iter.hashKeyIter = ((HashMap)((VMHashInstance)agg).storage.clone()).keySet().iterator();
3811+
iter.hashKeyIter = storage.keySet().iterator();
38093812
iter.iterMode = VMIterInstance.MODE_HASH;
38103813
return iter;
38113814
}
@@ -7023,12 +7026,12 @@ public static long coerce_n2i(double in) {
70237026
return Long.MIN_VALUE;
70247027
}
70257028
else {
7026-
return new Double(in).longValue();
7029+
return Double.valueOf(in).longValue();
70277030
}
70287031
}
70297032

70307033
public static double coerce_i2n(long in) {
7031-
return new Long(in).doubleValue();
7034+
return Long.valueOf(in).doubleValue();
70327035
}
70337036

70347037
/* Long literal workaround. */
@@ -7387,7 +7390,7 @@ public static SixModelObject loadcompunit(SixModelObject obj, long compileeHLL,
73877390
try {
73887391
EvalResult res = (EvalResult)obj;
73897392
Class<?> cuClass = tc.gc.byteClassLoader.defineClass(res.jc.name, res.jc.bytes);
7390-
res.cu = (CompilationUnit) cuClass.newInstance();
7393+
res.cu = (CompilationUnit) cuClass.getDeclaredConstructor().newInstance();
73917394
if (compileeHLL != 0)
73927395
usecompileehllconfig(tc);
73937396
res.cu.initializeCompilationUnit(tc);
@@ -7396,11 +7399,8 @@ public static SixModelObject loadcompunit(SixModelObject obj, long compileeHLL,
73967399
res.jc = null;
73977400
return obj;
73987401
}
7399-
catch (ControlException e) {
7400-
throw e;
7401-
}
74027402
catch (Exception e) {
7403-
throw new RuntimeException(e);
7403+
throw ExceptionHandling.dieInternal(tc, e);
74047404
}
74057405
}
74067406
public static long iscompunit(SixModelObject obj, ThreadContext tc) {

src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/CPPStruct.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,10 @@ public SixModelObject allocate(ThreadContext tc, STable st) {
8585
CPPStructREPRData repr_data = (CPPStructREPRData) st.REPRData;
8686
obj.st = st;
8787
try {
88-
obj.storage = (Structure) repr_data.structureClass.newInstance();
88+
obj.storage = (Structure) repr_data.structureClass.getDeclaredConstructor().newInstance();
8989
}
90-
catch (InstantiationException | IllegalAccessException e) {
91-
e.printStackTrace();
92-
throw new RuntimeException(e);
90+
catch (ReflectiveOperationException e) {
91+
throw ExceptionHandling.dieInternal(tc, e);
9392
}
9493
return obj;
9594
}

src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/CStruct.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,10 @@ public SixModelObject allocate(ThreadContext tc, STable st) {
8585
CStructREPRData repr_data = (CStructREPRData) st.REPRData;
8686
obj.st = st;
8787
try {
88-
obj.storage = (Structure) repr_data.structureClass.newInstance();
88+
obj.storage = (Structure) repr_data.structureClass.getDeclaredConstructor().newInstance();
8989
}
90-
catch (InstantiationException | IllegalAccessException e) {
91-
e.printStackTrace();
92-
throw new RuntimeException(e);
90+
catch (ReflectiveOperationException e) {
91+
throw ExceptionHandling.dieInternal(tc, e);
9392
}
9493
return obj;
9594
}

src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/CUnion.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,10 @@ public SixModelObject allocate(ThreadContext tc, STable st) {
8282
CUnionREPRData repr_data = (CUnionREPRData) st.REPRData;
8383
obj.st = st;
8484
try {
85-
obj.storage = (Union) repr_data.structureClass.newInstance();
85+
obj.storage = (Union) repr_data.structureClass.getDeclaredConstructor().newInstance();
8686
}
87-
catch (InstantiationException | IllegalAccessException e) {
88-
e.printStackTrace();
89-
throw new RuntimeException(e);
87+
catch (ReflectiveOperationException e) {
88+
throw ExceptionHandling.dieInternal(tc, e);
9089
}
9190
return obj;
9291
}

src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/P6Opaque.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,15 @@ private void installJVMType(ThreadContext tc, STable st, List<AttrInfo> attrInfo
258258

259259
((P6OpaqueREPRData)st.REPRData).jvmClass = use;
260260
try {
261-
((P6OpaqueREPRData)st.REPRData).instance = (P6OpaqueBaseInstance)((P6OpaqueREPRData)st.REPRData).jvmClass.newInstance();
261+
((P6OpaqueREPRData)st.REPRData).instance =
262+
(P6OpaqueBaseInstance)((P6OpaqueREPRData)st.REPRData).jvmClass.getDeclaredConstructor().newInstance();
262263
}
263-
catch (InstantiationException | IllegalAccessException e) {
264-
throw new RuntimeException(e);
264+
catch (ReflectiveOperationException e) {
265+
throw ExceptionHandling.dieInternal(tc, e);
266+
}
267+
finally {
268+
((P6OpaqueREPRData)st.REPRData).instance.st = st;
265269
}
266-
((P6OpaqueREPRData)st.REPRData).instance.st = st;
267270
}
268271

269272
private Class<?> generateJVMClass(ThreadContext tc, List<AttrInfo> attrInfoList) {

src/vm/jvm/runtime/org/raku/nqp/sixmodel/reprs/P6OpaqueBaseInstance.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,7 @@ public SixModelObject cas_attribute_boxed(ThreadContext tc, SixModelObject class
130130
catch (Exception e) {
131131
throw ExceptionHandling.dieInternal(tc, e);
132132
}
133-
finally {
134-
return result == null ? Ops.createNull(tc) : result;
135-
}
133+
return result == null ? Ops.createNull(tc) : result;
136134
}
137135

138136
@Override
@@ -161,9 +159,7 @@ public SixModelObject atomic_load_attribute_boxed(ThreadContext tc, SixModelObje
161159
catch (Exception e) {
162160
throw ExceptionHandling.dieInternal(tc, e);
163161
}
164-
finally {
165-
return result == null ? Ops.createNull(tc) : result;
166-
}
162+
return result == null ? Ops.createNull(tc) : result;
167163
}
168164

169165
public SixModelObject posDelegate() {

0 commit comments

Comments
 (0)