From d4f5b8af587794dd6f84eedeb2aeee1466e4395b Mon Sep 17 00:00:00 2001 From: wangxiang <276644985haidnor@gmail.com> Date: Sun, 30 Jul 2023 10:55:28 +0800 Subject: [PATCH] =?UTF-8?q?fix=20bug=20=E4=BF=AE=E5=A4=8D=20ClassLoader=20?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E4=B8=8D=E5=88=B0=E8=87=AA=E8=BA=AB=20jar=20?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=86=85=E7=9A=84=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/haidnor/jvm/classloader/ClassLoader.java | 11 ++--------- src/test/java/haidnor/jvm/test/TestJVM.java | 2 +- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/main/java/haidnor/jvm/classloader/ClassLoader.java b/src/main/java/haidnor/jvm/classloader/ClassLoader.java index 8517586..f4f37de 100644 --- a/src/main/java/haidnor/jvm/classloader/ClassLoader.java +++ b/src/main/java/haidnor/jvm/classloader/ClassLoader.java @@ -23,17 +23,10 @@ public class ClassLoader { public JarFile jarFile = null; static { - URL resource = ClassLoader.class.getResource("/"); - String path = resource.getPath(); - FileInputStream fis; - try { - fis = new FileInputStream(path + "/haidnorJVM.properties"); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } + InputStream is = ClassLoader.class.getResourceAsStream("/haidnorJVM.properties"); Properties properties = new Properties(); try { - properties.load(fis); + properties.load(is); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/test/java/haidnor/jvm/test/TestJVM.java b/src/test/java/haidnor/jvm/test/TestJVM.java index 8b0c62b..41ec9b2 100644 --- a/src/test/java/haidnor/jvm/test/TestJVM.java +++ b/src/test/java/haidnor/jvm/test/TestJVM.java @@ -142,7 +142,7 @@ public class TestJVM { runMainClass(demo_finally_2.class); } - @Test + @Test(expected = ArithmeticException.class) public void demo_finally_3() throws Exception { runMainClass(demo_finally_3.class); }