Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InputStream may leak in JarClassPath openClassfile #222

Closed
gzqreder opened this issue Sep 14, 2018 · 2 comments
Closed

InputStream may leak in JarClassPath openClassfile #222

gzqreder opened this issue Sep 14, 2018 · 2 comments

Comments

@gzqreder
Copy link

I use javassist to modify method in jar. The jar file which to be modified will be opened after process.

It will return JarURLInputStream When jar file is opened by openClassfile of JarClassPath.
It will check cache when JarURLInputStream close.

class JarURLInputStream extends java.io.FilterInputStream {
    JarURLInputStream (InputStream src) {
        super (src);
    }
    public void close () throws IOException {
        try {
            super.close();
        } finally {
            if (!getUseCaches()) {
                jarFile.close();
            }
        }
    }
}

I modified openClassfile in JarClassPath like this. It will be ok.

public InputStream openClassfile(String classname) throws NotFoundException
{
    URL jarURL = find(classname);
    if (null != jarURL)
        try {
            URLConnection urlConnection = jarURL.openConnection();
            urlConnection.setUseCaches(false);
            return urlConnection.getInputStream();
        }
        catch (IOException e) {
            throw new NotFoundException("broken jar file?: "
                    + classname);
        }
    return null;
}
@chibash
Copy link
Member

chibash commented Sep 15, 2018

OK, I've fixed it.

@chibash
Copy link
Member

chibash commented Sep 1, 2019

The previous fix was reverted.
To disable the cache, do javassist.ClassPool.cacheOpenedJarFile = false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants