1

我刚刚尝试扩展 SocketChannel,但似乎 SocketChannel 从 JRE 1.7.4 (http://openjdk.java.net/projects/nio/javadoc/java/nio/channels/SocketChannel.html) 开始提供了一些新的 API 方法,问题是如果我实现这些方法,每当我使用 Java 1.6 时,我的 JAR 都会抛出以下错误

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

现在我弄清楚了为什么会出现与“java/nio/channels/NetworkChannel”相关的错误,看来 SocketChannel 接口 NetworkChannel 从 JRE 1.7 开始

现在,当我使用 JRE 1.7.4+ 时,会发生一些运行时错误,实际上奇怪的是,即使我实现了那些新的 API 方法,但当我调用“unwrap”方法时我会遇到运行时错误

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)

在那一行我只调用 sslEngine.unwrap 方法,所以简而言之,当我实现了新的 API 方法时,它只适用于 JRE 1.7.0 到 1.7.3

如何使我的 JAR 与 JRE 1.6 和 1.7 兼容,同时扩展 SocketChannel 类?

4

1 回答 1

1

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 (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7142172) but it really seems to be

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

thanks for your patience

于 2012-10-11T16:21:46.677 回答