我刚尝试扩展SocketChannel,但似乎SocketChannel从JRE 1.7.4开始提供了一些新的API方法(http://openjdk.java.net/projects/nio/javadoc/java/nio/channels/SocketChannel。 html),问题是如果我实现这些方法,每当我使用Java 1.6时,我的JAR都会抛出以下错误
Exception in thread "Thread-24" java.lang.NoClassDefFoundError: java/nio/channels/NetworkChannel
现在我弄清楚为什么会出现与“java / nio / channels / NetworkChannel”相关的错误,看来SocketChannel从JRE 1.7开始接口NetworkChannel
现在,当我使用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
如何在扩展SocketChannel类的同时使JAR与JRE 1.6和1.7兼容?
答案 0 :(得分:1)
好的,似乎我已经确定了JRE 1.7.4+上的运行时错误问题,看起来它并不是真正的解包错误,而是证书错误,我再次遇到以下错误当我调用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(....)
傻傻的我应该注意到“由...引起”的短语,因为我在下面有这个代码,所以看起来从JRE 1.7.4开始,如果我在getAcceptedIssuers()中抛出异常那么我就会遇到这个问题,所以我最终没有抛出异常,而是返回null。我不确定1.7.4+问题是否与此修复有关(http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7142172)但它似乎确实是
public java.security.cert.X509Certificate[] getAcceptedIssuers()
{
return null;
//throw new UnsupportedOperationException();
}
感谢您的耐心