diff options
author | makamys <makamys@outlook.com> | 2023-02-10 01:41:21 +0100 |
---|---|---|
committer | makamys <makamys@outlook.com> | 2023-02-10 02:08:01 +0100 |
commit | 74c216c79309e474a0bc424ce08796659cf0c226 (patch) | |
tree | c0670f549d028198556a1c1d7fed042b84e84f96 /src/main/java/makamys | |
parent | d46b730176dba4ae87cd90b3802f54052426fc85 (diff) | |
download | Neodymium-74c216c79309e474a0bc424ce08796659cf0c226.tar.gz Neodymium-74c216c79309e474a0bc424ce08796659cf0c226.tar.bz2 Neodymium-74c216c79309e474a0bc424ce08796659cf0c226.zip |
Fix FC compat causing NPE
Happened with the following mod list:
_unimixins-compat-1.7.10-0.1.jar
_unimixins-gtnhmixins-1.7.10-0.1+2.1.9.jar
_unimixins-mixin-1.7.10-0.1+unimix-0.11.6.jar
_unimixins-mixingasm-1.7.10-0.1+0.2.2.jar
_unimixins-spongemixins-1.7.10-0.1+gtnh-2.0.1.jar
fastcraft-1.25.jar
neodymium-1.7.10-0.1.6-7-gd46b730+nomixin.jar
Diffstat (limited to 'src/main/java/makamys')
4 files changed, 58 insertions, 27 deletions
diff --git a/src/main/java/makamys/neodymium/Compat.java b/src/main/java/makamys/neodymium/Compat.java index 95c6ff4..e6bedea 100644 --- a/src/main/java/makamys/neodymium/Compat.java +++ b/src/main/java/makamys/neodymium/Compat.java @@ -86,7 +86,7 @@ public class Compat { public InputStream getInputStream(String path) { if(path.equals("/optifine/OptiFineForgeTweaker.class")) { // Dummy file to make FastCraft think OptiFine is present. - LOGGER.info("Returning a dummy /optifine/OptiFineForgeTweaker.class to force FastCraft compat."); + LOGGER.debug("Returning a dummy /optifine/OptiFineForgeTweaker.class to force FastCraft compat."); return new ByteArrayInputStream(new byte[0]); } else { return null; diff --git a/src/main/java/makamys/neodymium/util/virtualjar/IVirtualJar.java b/src/main/java/makamys/neodymium/util/virtualjar/IVirtualJar.java index 11cef7e..dbc4ca9 100644 --- a/src/main/java/makamys/neodymium/util/virtualjar/IVirtualJar.java +++ b/src/main/java/makamys/neodymium/util/virtualjar/IVirtualJar.java @@ -6,6 +6,14 @@ public interface IVirtualJar { public String getName(); + public default boolean hasFile(String path) { + try(InputStream is = getInputStream(path)) { + return is != null; + } catch(Exception e) { + return false; + } + } + public InputStream getInputStream(String path); } diff --git a/src/main/java/makamys/neodymium/util/virtualjar/VirtualJar.java b/src/main/java/makamys/neodymium/util/virtualjar/VirtualJar.java index 8350d6f..d5049b4 100644 --- a/src/main/java/makamys/neodymium/util/virtualjar/VirtualJar.java +++ b/src/main/java/makamys/neodymium/util/virtualjar/VirtualJar.java @@ -3,6 +3,7 @@ package makamys.neodymium.util.virtualjar; import static makamys.neodymium.Constants.MODID; import static makamys.neodymium.Constants.PROTOCOL; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; @@ -65,35 +66,56 @@ public class VirtualJar { public static class StreamHandlerImpl implements Handler.IURLStreamHandlerImpl { @Override - public URLConnection openConnection(URL url) { - return new URLConnection(url) { - public void connect() { - + public URLConnection openConnection(URL url) throws IOException { + return new VirtualJarConnection(url); + } + + public static class VirtualJarConnection extends URLConnection { + + IVirtualJar jar; + private String filePath; + + public VirtualJarConnection(URL url) throws IOException { + super(url); + + String path = url.getPath(); + String nameSuffix = ".jar!"; + int nameEnd = path.indexOf(nameSuffix); + String name = path.substring(0, nameEnd); + + jar = jars.get(name); + + if(jar == null) { + throw new IOException(); } - - public Object getContent() throws IOException { - return super.getContent(); + + filePath = path.substring(nameEnd + nameSuffix.length()); + + if(!jar.hasFile(filePath)) { + throw new IOException(); } + } + + public void connect() throws IOException { + + } - public String getHeaderField(String name) { - return super.getHeaderField(name); - } + public Object getContent() throws IOException { + return super.getContent(); + } - public InputStream getInputStream() { - String path = getURL().getPath(); - String nameSuffix = ".jar!"; - int nameEnd = path.indexOf(nameSuffix); - String name = path.substring(0, nameEnd); - - IVirtualJar jar = jars.get(name); - - return jar.getInputStream(path.substring(nameEnd + nameSuffix.length())); - } + public String getHeaderField(String name) { + return super.getHeaderField(name); + } - public java.io.OutputStream getOutputStream() throws IOException { - return super.getOutputStream(); - } - }; + public InputStream getInputStream() { + return jar.getInputStream(filePath); + } + + public java.io.OutputStream getOutputStream() throws IOException { + return super.getOutputStream(); + } + } } diff --git a/src/main/java/makamys/neodymium/util/virtualjar/protocol/neodymiumvirtualjar/Handler.java b/src/main/java/makamys/neodymium/util/virtualjar/protocol/neodymiumvirtualjar/Handler.java index 9f0fe66..4e156ff 100644 --- a/src/main/java/makamys/neodymium/util/virtualjar/protocol/neodymiumvirtualjar/Handler.java +++ b/src/main/java/makamys/neodymium/util/virtualjar/protocol/neodymiumvirtualjar/Handler.java @@ -3,6 +3,7 @@ package makamys.neodymium.util.virtualjar.protocol.neodymiumvirtualjar; import static makamys.neodymium.Constants.MODID; import static makamys.neodymium.Constants.PROTOCOL; +import java.io.IOException; import java.net.URL; import java.net.URLConnection; import java.net.URLStreamHandler; @@ -14,11 +15,11 @@ public class Handler extends URLStreamHandler { private static final IURLStreamHandlerImpl impl = (IURLStreamHandlerImpl)Launch.blackboard.get(MODID + "." + PROTOCOL + ".impl"); @Override - protected URLConnection openConnection(URL url) { + protected URLConnection openConnection(URL url) throws IOException { return impl.openConnection(url); } public interface IURLStreamHandlerImpl { - URLConnection openConnection(URL url); + URLConnection openConnection(URL url) throws IOException; } } |