code review request: 7054428: test/java/security/SecureClassLoader/ error

Weijun Wang at
Wed Jun 15 04:47:40 PDT 2011

I've just tried

     try (FileInputStream fin = new FileInputStream(f);
             FileChannel fc = fin.getChannel()) {
         return, 0, fc.size());

and it succeeds.

So both the channel and stream can be closed and the file mapping is 
still usable?


On 06/15/2011 07:26 PM, Alan Bateman wrote:
> Weijun Wang wrote:
>> But the current test passes without closing the stream, even on
>> Windows. I guess it's because the file opened is not in scratch
>> directory and needs not be cleaned up.
>> If we have to close the stream/channel, it seems the references need
>> to saved in DummyClassLoader's static fields and cleaned up in another
>> static method called in a finally clause of the test's main method.
>> The reason the original test failed in samevm is that
>> buffers[DIRECT_BUFFER].flip() is not called and its remaining() is
>> zero, and causes the error:
>> java.lang.ClassFormatError: Truncated class file
> You are right, the file is the test.src directory and so isn't subject
> to the clean-up. In that case I'm okay with the proposed changes. I do
> think we should still close the FileChannel in readClassFile. Once a
> file mapping is created then the FileChannel can be closed and this
> would help avoid open file descriptors building up - this can happen
> when running hunreds of tests in the same VM.
> -Alan.

More information about the security-dev mailing list