最近将应用程序从 Oracle Java 9 更新到 AdoptJDk 11.0.6,我现在看到以下代码形式的错误:
public static String convertWikidataUrl(String wikidataUrl)
{
String qPage = wikidataUrl.substring(wikidataUrl.lastIndexOf('/') + 1);
String apiUrl = WIKIDATA_IMAGE_API_URL + qPage;
try
{
URL url = new URL(apiUrl);
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
int responseCode = uc.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK)
{
MainWindow.logger.severe(":ResponseCode:"+responseCode);
}
//Everything ok so continue
BufferedInputStream bis = new BufferedInputStream(uc.getInputStream());
JAXBContext jc = getWikidataInitialContext();
Unmarshaller um = jc.createUnmarshaller();
Api api = (Api) um.unmarshal(bis);
if(api.getClaims()!=null
&& api.getClaims().getProperty()!=null
&& api.getClaims().getProperty().getClaim()!=null
&& api.getClaims().getProperty().getClaim().getMainsnak()!=null
&& api.getClaims().getProperty().getClaim().getMainsnak().getDatavalue()!=null)
{
return api.getClaims().getProperty().getClaim().getMainsnak().getDatavalue().getValue();
}
else
{
return null;
}
}
catch (JAXBException e)
{
MainWindow.logger.log(Level.SEVERE, e.getMessage(), e);
}
catch (MalformedURLException mue)
{
MainWindow.logger.log(Level.SEVERE, mue.getMessage(), mue);
}
catch (Exception ex)
{
MainWindow.logger.log(Level.SEVERE, ex.getMessage(), ex);
}
return null;
}
失败:
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:131)
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:307)
at java.base/sun.security.ssl.Alert$AlertConsumer.consume(Alert.java:291)
at java.base/sun.security.ssl.TransportContext.dispatch(TransportContext.java:180)
at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:164)
at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1151)
at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1062)
at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:402)
at java.base/sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:567)
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1587)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1515)
at java.base/java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:527)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:334)
at com.jthink.songkong.analyse.musicbrainz.WikipediaImage.convertWikipediaUrl(WikipediaImage.java:49)
at com.jthink.songkong.analyse.musicbrainz.ArtistArtwork.findArtistImageLink(ArtistArtwork.java:54)
at com.jthink.songkong.analyse.musicbrainz.ArtistArtworkOnlineLookup.call(ArtistArtworkOnlineLookup.java:63)
at com.jthink.songkong.analyse.musicbrainz.ArtistArtworkOnlineLookup.call(ArtistArtworkOnlineLookup.java:26)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
该问题已在 Windows 上出现,但也可能出现在其他平台上
该错误肯定是由于更改了 JRE,但我不知道问题是从 Java 9 转移到 11,还是从 Oracle 转移到 AdoptJdk,我该如何解决?
更新
- 在使用 11.0.6 的 MacOS 上不会出现此问题
- 在 Windows 上从 11.0.6 更新到 11.0.7 没有效果
- 在 Windows 上添加 -Dhttps.protocols=TLSv1.1,TLSv1.2(禁用 TLS1.3 支持)解决了这个问题。
- 此错误的可能版本https://bugs.openjdk.java.net/browse/JDK-8206923