Merge pull request #124 from sdgx/missing-check-against-null
Add missing checks against null
This commit is contained in:
@@ -30,8 +30,11 @@ public class GarbageCollector
|
|||||||
}
|
}
|
||||||
|
|
||||||
File folder = file.getParentFile();
|
File folder = file.getParentFile();
|
||||||
if (folder.list().length == 0) {
|
if (folder != null) {
|
||||||
FileUtil.deleteHarder(folder);
|
String[] children = folder.list();
|
||||||
|
if (children != null && children.length == 0) {
|
||||||
|
FileUtil.deleteHarder(folder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ public class GetdownApp
|
|||||||
String[] cmdarray;
|
String[] cmdarray;
|
||||||
if (RunAnywhere.isWindows()) {
|
if (RunAnywhere.isWindows()) {
|
||||||
String osName = System.getProperty("os.name");
|
String osName = System.getProperty("os.name");
|
||||||
if (osName.indexOf("9") != -1 || osName.indexOf("Me") != -1) {
|
if (osName != null && (osName.indexOf("9") != -1 || osName.indexOf("Me") != -1)) {
|
||||||
cmdarray = new String[] {
|
cmdarray = new String[] {
|
||||||
"command.com", "/c", "start", "\"" + url + "\"" };
|
"command.com", "/c", "start", "\"" + url + "\"" };
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -93,9 +93,12 @@ public class GetdownApplet extends JApplet
|
|||||||
// getSigners() returns all certificates used to sign this applet which may allow a
|
// getSigners() returns all certificates used to sign this applet which may allow a
|
||||||
// third party to insert a trusted certificate. This should be avoided.
|
// third party to insert a trusted certificate. This should be avoided.
|
||||||
log.warning("No resource certificate found, falling back to class signers");
|
log.warning("No resource certificate found, falling back to class signers");
|
||||||
for (Object signer : GetdownApplet.class.getSigners()) {
|
Object[] candidates = GetdownApplet.class.getSigners();
|
||||||
if (signer instanceof Certificate) {
|
if (candidates != null) {
|
||||||
signers.add((Certificate)signer);
|
for (Object signer : candidates) {
|
||||||
|
if (signer instanceof Certificate) {
|
||||||
|
signers.add((Certificate)signer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -307,7 +310,11 @@ public class GetdownApplet extends JApplet
|
|||||||
protected static Certificate loadCertificate (String path)
|
protected static Certificate loadCertificate (String path)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
URL keyUrl = GetdownApplet.class.getClassLoader().getResource(path);
|
ClassLoader classLoader = GetdownApplet.class.getClassLoader();
|
||||||
|
if (classLoader == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
URL keyUrl = classLoader.getResource(path);
|
||||||
if (keyUrl == null) {
|
if (keyUrl == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -233,7 +233,7 @@ public class JarDiff implements JarDiffCodes
|
|||||||
jos.write(bytes, 0, bytes.length);
|
jos.write(bytes, 0, bytes.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void writeEscapedString (Writer writer, String string)
|
protected static Writer writeEscapedString (Writer writer, String string)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
int index = 0;
|
int index = 0;
|
||||||
@@ -251,13 +251,15 @@ public class JarDiff implements JarDiffCodes
|
|||||||
index++;
|
index++;
|
||||||
writer.write('\\');
|
writer.write('\\');
|
||||||
}
|
}
|
||||||
if (last != 0) {
|
if (last != 0 && chars != null) {
|
||||||
writer.write(chars, last, chars.length - last);
|
writer.write(chars, last, chars.length - last);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// no spaces
|
// no spaces
|
||||||
writer.write(string);
|
writer.write(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return writer;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void writeEntry (JarOutputStream jos, JarEntry entry, JarFile2 file)
|
private static void writeEntry (JarOutputStream jos, JarEntry entry, JarFile2 file)
|
||||||
|
|||||||
@@ -152,6 +152,10 @@ public class JarDiffPatcher implements JarDiffCodes
|
|||||||
while (iEntries.hasNext()) {
|
while (iEntries.hasNext()) {
|
||||||
String name = iEntries.next();
|
String name = iEntries.next();
|
||||||
JarEntry entry = oldJar.getJarEntry(name);
|
JarEntry entry = oldJar.getJarEntry(name);
|
||||||
|
if (entry == null) {
|
||||||
|
// names originally retrieved from the JAR, so this should never happen
|
||||||
|
throw new AssertionError("JAR entry not found: " + name);
|
||||||
|
}
|
||||||
updateObserver(observer, currentEntry, size);
|
updateObserver(observer, currentEntry, size);
|
||||||
currentEntry++;
|
currentEntry++;
|
||||||
writeEntry(jos, entry, oldJar);
|
writeEntry(jos, entry, oldJar);
|
||||||
|
|||||||
@@ -187,14 +187,20 @@ public class FileUtil
|
|||||||
*/
|
*/
|
||||||
public static void walkTree (File root, Visitor visitor)
|
public static void walkTree (File root, Visitor visitor)
|
||||||
{
|
{
|
||||||
Deque<File> stack = new ArrayDeque<>(Arrays.asList(root.listFiles()));
|
File[] children = root.listFiles();
|
||||||
while (!stack.isEmpty()) {
|
if (children != null) {
|
||||||
File currentFile = stack.pop();
|
Deque<File> stack = new ArrayDeque<>(Arrays.asList(children));
|
||||||
if (currentFile.exists()) {
|
while (!stack.isEmpty()) {
|
||||||
visitor.visit(currentFile);
|
File currentFile = stack.pop();
|
||||||
if (currentFile.isDirectory()) {
|
if (currentFile.exists()) {
|
||||||
for (File file: currentFile.listFiles()) {
|
visitor.visit(currentFile);
|
||||||
stack.push(file);
|
if (currentFile.isDirectory()) {
|
||||||
|
File[] currentChildren = currentFile.listFiles();
|
||||||
|
if (currentChildren != null) {
|
||||||
|
for (File file : currentChildren) {
|
||||||
|
stack.push(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,8 +182,13 @@ public class LaunchUtil
|
|||||||
*/
|
*/
|
||||||
public static boolean mustMonitorChildren ()
|
public static boolean mustMonitorChildren ()
|
||||||
{
|
{
|
||||||
String osname = System.getProperty("os.name").toLowerCase();
|
String osname = System.getProperty("os.name");
|
||||||
return (osname.indexOf("windows 98") != -1 || osname.indexOf("windows me") != -1);
|
if (osname != null) {
|
||||||
|
osname = osname.toLowerCase();
|
||||||
|
return (osname.indexOf("windows 98") != -1 || osname.indexOf("windows me") != -1);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
//
|
||||||
|
// Getdown - application installer, patcher and launcher
|
||||||
|
// Copyright (C) 2004-2016 Getdown authors
|
||||||
|
// https://github.com/threerings/getdown/blob/master/LICENSE
|
||||||
|
|
||||||
|
package com.threerings.getdown.tools;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static com.threerings.getdown.tools.JarDiff.writeEscapedString;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests {@link JarDiff}.
|
||||||
|
*/
|
||||||
|
public class JarDiffTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWriteEscapedString () throws IOException
|
||||||
|
{
|
||||||
|
assertEquals("abc", writeEscapedString(new StringWriter(), "abc").toString());
|
||||||
|
assertEquals("abc\\ xyz", writeEscapedString(new StringWriter(), "abc xyz").toString());
|
||||||
|
assertEquals("\\ xyz", writeEscapedString(new StringWriter(), " xyz").toString());
|
||||||
|
assertEquals("abc\\ ", writeEscapedString(new StringWriter(), "abc ").toString());
|
||||||
|
assertEquals("\\ ", writeEscapedString(new StringWriter(), " ").toString());
|
||||||
|
assertEquals("", writeEscapedString(new StringWriter(), "").toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user