aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/javassist/JvstTest.java
diff options
context:
space:
mode:
authorShigeru Chiba <chibash@users.noreply.github.com>2018-05-07 19:06:13 +0900
committerGitHub <noreply@github.com>2018-05-07 19:06:13 +0900
commit1513c3372bc674d9f9f7ff7cb258ab9b1ccb68c1 (patch)
treed408d1fbcea7ae0545c0e04547b7c203545560b7 /src/test/javassist/JvstTest.java
parent40d3223b128887dffafb8d6f28438628ad72e039 (diff)
parent620a8be65bb786c77fc2016e9a53364f3d65260e (diff)
downloadjavassist-1513c3372bc674d9f9f7ff7cb258ab9b1ccb68c1.tar.gz
javassist-1513c3372bc674d9f9f7ff7cb258ab9b1ccb68c1.zip
Merge pull request #168 from cmelchior/cm/bug/classpath-close
[WIP] Fix leaking file handlers
Diffstat (limited to 'src/test/javassist/JvstTest.java')
-rw-r--r--src/test/javassist/JvstTest.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/test/javassist/JvstTest.java b/src/test/javassist/JvstTest.java
index d28c0654..ff58106a 100644
--- a/src/test/javassist/JvstTest.java
+++ b/src/test/javassist/JvstTest.java
@@ -1,7 +1,9 @@
package javassist;
import junit.framework.*;
+import java.io.File;
import java.io.FileInputStream;
+import java.io.InputStream;
import java.lang.reflect.Method;
import javassist.bytecode.*;
import javassist.expr.*;
@@ -64,6 +66,36 @@ public class JvstTest extends JvstTestRoot {
assertTrue("[class path: ]".equals(pool.toString()));
}
+ public void testReleaseJarClassPathFileHandle() throws Exception {
+ String jarFileName = "./empty.jar";
+ ClassLoader classLoader = getClass().getClassLoader();
+ File jarFile = new File(classLoader.getResource(jarFileName).getFile());
+ assertTrue(jarFile.exists());
+
+ // Prepare class pool and force it to open the Jar file
+ ClassPool pool = ClassPool.getDefault();
+ ClassPath cp = pool.appendClassPath(jarFile.getAbsolutePath());
+ assertNull(cp.openClassfile("nothere.Dummy"));
+
+ // Assert that it is possible to delete the jar file.
+ // On Windows deleting an open file will fail, while on on Mac/Linux this is always possible.
+ // This check will thus only fail on Windos if the file is still open.
+ assertTrue(jarFile.delete());
+ }
+
+ public void testJarClassPath() throws Exception {
+ String jarFileName = "./simple.jar";
+ ClassLoader classLoader = getClass().getClassLoader();
+ File jarFile = new File(classLoader.getResource(jarFileName).getFile());
+ assertTrue(jarFile.exists());
+
+ ClassPool pool = ClassPool.getDefault();
+ ClassPath cp = pool.appendClassPath(jarFile.getAbsolutePath());
+ InputStream is = cp.openClassfile("com.test.Test");
+ assertNotNull(is);
+ is.close();
+ }
+
public void testSubtype() throws Exception {
CtClass cc = sloader.get("test1.Subtype");
assertTrue(cc.subtypeOf(cc));