[ 
http://issues.apache.org/jira/browse/DERBY-1338?page=comments#action_12413021 ] 

Dag H. Wanvik commented on DERBY-1338:
--------------------------------------

Thanks for the suggestion Bryan. I tried it, but in that case the socket read 
returns -1 (end of data) and all is well. So i had to do some more digging.

It seems clear that this is bug in the classloader.  I suggest a
simple workaround, see below.

I compiled my own version of URLClassLoader so I could see what
happens when the class fails to load and I found that the reading of
the actual bytes of the class fails with java.io.InterruptedIOException:

java/net/URLClassLoader.java (JDK 1.5)
                    :
line 214           private Class defineClass(String name, Resource res) throws 
IOException {
                       :
line 256               byte[] b = res.getBytes();
                                      **
We get java.io.InterruptedIOException here. This in turn causes
URLClassLoader#findClass to throw ClassNotFoundException:

line 184           protected Class<?> findClass(final String name) 
                       throws ClassNotFoundException
                       :
line 194                    try {
                                return defineClass(name, res);
                            } catch (IOException e) {
                                throw new ClassNotFoundException(name, e);
                            }


The shutdown of the server *has* interrupted the thread, in
NetworkServerStarter#blockingStart. So, is this the reason we get this
exception? Most likely. I googled and found relevant these bug
reports:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4549130
        URLClassLoader: NoClassDefFoundError thrown when not using rt.jar
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4764778
        Interrupted thread can't load classes from classes directory (sol)
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4385444
        (spec) InterruptedIOException should not be required by platform 
specification (sol)
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6375934
        thread interruption interferes with classloading (sol)

I quote from the first:

> On Solaris java.io is interruptible. Therefore, if you
> read class from a classfile and the thread gets interrupted,
> one gets an InterruptedIOException.
> One needs to catch InterruptedIOException in defineClass
> of URLClassLoader and then retry.

A simple repro is enclosed:

----------------------------------------
public class Test {
    public static void main(String[] args) {
        new HappyClass();
        Thread.currentThread().interrupt();
        new UnhappyClass();
    }
}
        
class HappyClass {}
class UnhappyClass {}
----------------------------------------

The second issue indicates that this has been fixed for Mustang. 

In deed, when I run this repro, it fails on JDK1.5, but *not* on JDK
1.6. It would seem this is the root cause of our problem, and that
JDK1.6 does not have this problem. I checked the source for 1.6,
though, and the code in URLCLassLoader is unchanged, so presumably it
has been fixed somewhere else, the bug issue doesn't say how. 

However, http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6375934
dated Jan 2006, seems to say it has not been fully fixed, even in
1.6 - it seems to be gone, though :-)

It is a Solaris specific problem, according to CR 4385444, since under
other OSes, the interrupting of a Java thread goes not give rise to
the InterruptedIOException.

Again, this has not been seen when running from jars, but I think it
is sufficiently annoying/risky that it would be nice to fix it, since
it will be some time before we only run on 1.6 :)

As I mentioned before, we can make sure the classes in question
(DRDAProtocolExceptionInfo and DRDAProtocolException) are already
loaded (by creating a dummy object) before the thread is interrupted,
thus sidestepping the issue.  If nobody objects, I will post a patch
with this solution.



> Client tests DerbyNetNewServer and NSinSameVM fail with NoClassDefFoundError: 
> DRDAProtocolExceptionInfo when run from classes dir
> ---------------------------------------------------------------------------------------------------------------------------------
>
>          Key: DERBY-1338
>          URL: http://issues.apache.org/jira/browse/DERBY-1338
>      Project: Derby
>         Type: Bug

>   Components: Regression Test Failure
>     Versions: 10.2.0.0
>  Environment: Sun JDK 1.4.2, Sun JDK 1.5
>     Reporter: Dag H. Wanvik
>     Priority: Minor
>      Fix For: 10.2.0.0

>
> When run from Sun JDK 1.4.2 and Sun JDK 1.5, these two tests fail when run 
> from the
> classes directory. They work, though, when run from jars.
> Running NSinSameVM in my sandbox:
> bash-3.00$ java   -Dframework=DerbyNetClient 
> org.apache.derbyTesting.functionTests.harness.RunTest 
> derbynet/NSinSameJVM.java
> *** Start: NSinSameJVM jdk1.4.2_05 DerbyNetClient 2006-05-22 14:49:05 ***
> Initialize for framework: DerbyNetClient
> startServer = false. Bypass server startup
> 6 add
> > java.lang.NoClassDefFoundError: 
> > org/apache/derby/impl/drda/DRDAProtocolExceptionInfo
> Test Failed.
> *** End:   NSinSameJVM jdk1.4.2_05 DerbyNetClient 2006-05-22 14:49:27 ***
> I get similar behavior for DerbyNetNewServer.  I ran this on a Solaris 
> 10/i86x box. Davis has seen it too, see 
> initial discusson on this thread: 
> http://www.nabble.com/forum/ViewPost.jtp?post=4477600&framed=y

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to