Code.Blodded
Code.Blodded

Reputation: 231

Extending SocketChannel in JRE 1.7.4+

I just tried extending SocketChannel but it seems that SocketChannel has some new API methods available starting from JRE 1.7.4 (SocketChannel). The problem is if I implement those methods, my JAR would throw the following error whenever I'm using Java 1.6

Exception in thread "Thread-24" java.lang.NoClassDefFoundError: java/nio/channels/NetworkChannel

Now I figured out why there is an error related to java/nio/channels/NetworkChannel, it appears that SocketChannel implements interface NetworkChannel starting on JRE 1.7

Now, when I'm using JRE 1.7.4+, some runtime error occurs. Actually the weird thing is even if I have those new API methods implemented then I'm getting runtime error when I call the unwrap method:

Exception in thread "Thread-27" java.lang.RuntimeException: Delegated task threw Exception/Error
    at sun.security.ssl.Handshaker.checkThrown(Unknown Source)
    at sun.security.ssl.SSLEngineImpl.checkTaskThrown(Unknown Source)
    at sun.security.ssl.SSLEngineImpl.readNetRecord(Unknown Source)
    at sun.security.ssl.SSLEngineImpl.unwrap(Unknown Source)
    at javax.net.ssl.SSLEngine.unwrap(Unknown Source)
    at CustomSocketChannel.unwrap(CustomSocketChannel.java:565)

On that line I just call the sslEngine.unwrap method. So in short when I have the new API methods implemented, it only works with JRE 1.7.0 to 1.7.3

How can I make my JAR compatible with JRE 1.6 and 1.7 while also extending the SocketChannel class?

Upvotes: 1

Views: 1220

Answers (1)

Code.Blodded
Code.Blodded

Reputation: 231

OK, it seems like I have pinpointed the issue about the runtime error on JRE 1.7.4+. It appears that it is not really the unwrapping error but rather the certificate error. Again I'm also getting the following error whenever I'm getting that runtime error when I call SSLEngine.unwrap:

Exception in thread "Thread-24" java.lang.RuntimeException: Delegated task threw Exception/Error
    at sun.security.ssl.Handshaker.checkThrown(Unknown Source)
    at sun.security.ssl.SSLEngineImpl.checkTaskThrown(Unknown Source)
    at sun.security.ssl.SSLEngineImpl.readNetRecord(Unknown Source)
    at sun.security.ssl.SSLEngineImpl.unwrap(Unknown Source)
    at javax.net.ssl.SSLEngine.unwrap(Unknown Source)
    .....
Caused by: java.lang.UnsupportedOperationException
    at ....RTMPSTrustManager.getAcceptedIssuers(....)

Silly me I should have noticed that "Caused by" phrase, since I have this code below, so it seems that starting from JRE 1.7.4. If I throw an exception inside getAcceptedIssuers() then I'll have that problem, so I just ended up not throwing an exception but returning null instead.

I'm not sure if that 1.7.4+ problem is related to this fix (JDK-7142172), but it really seems to be.

public java.security.cert.X509Certificate[] getAcceptedIssuers()
{
    return null;
    //throw new UnsupportedOperationException();
}

Upvotes: 1

Related Questions