]> source.dussan.org Git - aspectj.git/commitdiff
Simple regression test unit test for #266
authorAlexander Kriegisch <Alexander@Kriegisch.name>
Sun, 10 Dec 2023 02:31:35 +0000 (09:31 +0700)
committerAlexander Kriegisch <Alexander@Kriegisch.name>
Sun, 10 Dec 2023 02:50:33 +0000 (03:50 +0100)
Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
weaver/src/test/java/org/aspectj/weaver/bcel/ExtensibleURLClassLoaderTest.java [new file with mode: 0644]

diff --git a/weaver/src/test/java/org/aspectj/weaver/bcel/ExtensibleURLClassLoaderTest.java b/weaver/src/test/java/org/aspectj/weaver/bcel/ExtensibleURLClassLoaderTest.java
new file mode 100644 (file)
index 0000000..6136363
--- /dev/null
@@ -0,0 +1,51 @@
+/* *******************************************************************
+ * Copyright (c) 2023 Contributors
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v 2.0
+ * which accompanies this distribution and is available at
+ * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
+ * ******************************************************************/
+package org.aspectj.weaver.bcel;
+
+import junit.framework.TestCase;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+public class ExtensibleURLClassLoaderTest extends TestCase {
+  /**
+   * Simple regression test for <a href="https://github.com/eclipse-aspectj/aspectj/issues/266">GitHub issue 266</a>
+   */
+  public void testClassNotFoundExceptionHasRootCauseOnIOException() throws URISyntaxException, MalformedURLException {
+    ExtensibleURLClassLoader extensibleURLClassLoader = new MockExtensibleURLClassLoader(
+      new URL[] { new URI("file://dummy").toURL() },
+      null
+    );
+    ClassNotFoundException classNotFoundException = null;
+    try {
+      extensibleURLClassLoader.findClass(getClass().getName().replace('.', '/'));
+    } catch (ClassNotFoundException e) {
+      classNotFoundException = e;
+    }
+    assertNotNull(classNotFoundException);
+    Throwable cause = classNotFoundException.getCause();
+    assertNotNull(cause);
+    assertTrue(cause instanceof IOException);
+    assertEquals("uh-oh", cause.getMessage());
+  }
+
+  static class MockExtensibleURLClassLoader extends ExtensibleURLClassLoader {
+    public MockExtensibleURLClassLoader(URL[] urls, ClassLoader parent) {
+      super(urls, parent);
+    }
+
+    @Override
+    protected byte[] getBytes(String name) throws IOException {
+      throw new IOException("uh-oh");
+    }
+  }
+}