Skip to content

Commit 8e2092b

Browse files
committed
Solve remaining unchecked and deprecation warnings
Solve remaining unchecked and deprecation warnings
1 parent 2a42863 commit 8e2092b

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

CaDoodleUpdater/src/main/java/com/commonwealthrobotics/JvmManager.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,24 @@ public static String getCommandString(String project, String repo, String versio
7070
HashMap<String, Object> database = gson.fromJson(jsonText, TT_mapStringString);
7171
String key = "UNKNOWN";
7272
key = discoverKey(key);
73-
Map<String, Object> vm = (Map<String, Object>) database.get(key);
73+
Object rawKey = database.get(key); // raw lookup
74+
if (!(rawKey instanceof Map))
75+
throw new IllegalStateException("Entry for key '" + key + "' is not a Map");
76+
@SuppressWarnings("unchecked")
77+
Map<String, Object> vm = (Map<String, Object>) rawKey;
78+
7479
String baseURL = vm.get("url").toString();
7580
String type = vm.get("type").toString();
7681
String name = vm.get("name").toString();
7782
List<String> jvmargs = null;
7883
Object o = vm.get("jvmargs");
79-
if (o != null)
80-
jvmargs = (List<String>) o;
81-
else
84+
if (o instanceof List) {
85+
@SuppressWarnings("unchecked")
86+
List<String> tmp = (List<String>) o;
87+
jvmargs = tmp;
88+
} else
8289
jvmargs = new ArrayList<String>();
90+
8391
String jvmURL = baseURL + name + "." + type;
8492
jvmArchive = download("", jvmURL, 300000000, progress, bindir, name + "." + type);
8593
dest = new File(bindir + name);
@@ -178,7 +186,7 @@ private static void unzip(File path, String dir) throws Exception {
178186
ex.printStackTrace();
179187
}
180188
try (OutputStream out = new FileOutputStream(entryPath.toFile())) {
181-
IOUtils.copy(in, out);
189+
in.transferTo(out);
182190
}
183191
if (isExecutable(entry)) {
184192
entryPath.toFile().setExecutable(true);
@@ -204,7 +212,7 @@ public static void untar(File tarFile, String dir) throws Exception {
204212
tarFile.delete();
205213
return;
206214
}
207-
TarArchiveEntry tarEntry = tarIn.getNextTarEntry();
215+
TarArchiveEntry tarEntry = tarIn.getNextEntry();
208216
// tarIn is a TarArchiveInputStream
209217
while (tarEntry != null) {// create a file with the same name as the tarEntry
210218
File destPath = new File(dest.toString() + System.getProperty("file.separator") + tarEntry.getName());
@@ -225,7 +233,7 @@ public static void untar(File tarFile, String dir) throws Exception {
225233
destPath.setExecutable(true);
226234
}
227235
}
228-
tarEntry = tarIn.getNextTarEntry();
236+
tarEntry = tarIn.getNextEntry();
229237
}
230238
tarIn.close();
231239
}

0 commit comments

Comments
 (0)