You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JavaFX应用因WebCoreTestSupport::allowsAnySSLCertificate崩溃求助

MacBook Pro M3上JavaFX WebView多次重定向导致应用崩溃排查

问题描述

在MacBook Pro M3(macOS系统)上,通过IntelliJ运行使用WebView/WebEngine的JavaFX应用时,网页发生多次重定向后应用触发JVM致命错误并崩溃。

崩溃日志

# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x000000033fc621bc, pid=25361, tid=259
#
# JRE version: OpenJDK Runtime Environment Temurin-21.0.4+7 (21.0.4+7) (build 21.0.4+7-LTS)
# Java VM: OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (21.0.4+7-LTS, mixed mode, tiered, compressed oops, compressed class ptrs, g1 gc, bsd-aarch64)
# Problematic frame:
# C  [libjfxwebkit.dylib+0xc421bc]  WebCoreTestSupport::allowsAnySSLCertificate()+0x8e21f4
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# (removed)
[19.190s][warning][os] Loading hsdis library failed
#
# If you would like to submit a bug report, please visit:
#   https://github.com/adoptium/adoptium-support/issues
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Disconnected from the target VM, address: '127.0.0.1:56125', transport: 'socket'

Process finished with exit code 134 (interrupted by signal 6:SIGABRT)

核心代码

@FXML 
public WebView webView;

WebEngine webEngine;
String portalUrl = "some url";
String redirectUrl = "some url";

@Override
public void initialize(URL url, ResourceBundle resourceBundle){
    // Load webengine
    webEngine = webView.getEngine();
    addListeners();
}

...

private void addListeners() {
    // Add listener to the url property
    // If url changes, login was executed
    webEngine.locationProperty().addListener(
            new ChangeListener<String>() {
                @Override public void changed(ObservableValue ov, String oldState, String newState) {
                    if(oldState != null){
                        if (!oldState.equals(newState)) {
                            if(newState.indexOf(redirectUrl) == 0){ 
                                // We are on our final destination
                                // Do stuff
                                
                            }else if(newState.indexOf("?error=")>-1){
                                webEngine.load(portalUrl);
                            }
                        }
                    }
                }
            });

    if(!"".equals(portalUrl)){
        webEngine.load(portalUrl);
    }
}

环境信息

  • JDK:Adoptium Java 21.0.4 LTS
  • JavaFX:21.0.4
  • 已尝试切换至Java/JavaFX 17版本,问题仍未解决

排查建议

  • 修复监听器递归触发问题:当前代码在locationProperty监听器中调用webEngine.load(),可能在重定向过程中频繁触发加载操作,导致WebKit native层资源冲突。建议添加状态标志位避免递归:
    private boolean isLoading = false;
    
    private void addListeners() {
        webEngine.locationProperty().addListener((ov, oldState, newState) -> {
            if (oldState == null || oldState.equals(newState) || isLoading) {
                return;
            }
    
            if (newState.startsWith(redirectUrl)) {
                // 处理最终页面逻辑
            } else if (newState.contains("?error=")) {
                isLoading = true;
                webEngine.load(portalUrl);
                // 加载完成后重置状态
                webEngine.getLoadWorker().stateProperty().addListener((workerOv, oldWorkerState, newWorkerState) -> {
                    if (newWorkerState == Worker.State.SUCCEEDED || newWorkerState == Worker.State.FAILED) {
                        isLoading = false;
                    }
                });
            }
        });
    
        if (!portalUrl.isEmpty()) {
            isLoading = true;
            webEngine.load(portalUrl);
            webEngine.getLoadWorker().stateProperty().addListener((workerOv, oldWorkerState, newWorkerState) -> {
                if (newWorkerState == Worker.State.SUCCEEDED || newWorkerState == Worker.State.FAILED) {
                    isLoading = false;
                }
            });
        }
    }
    
  • 排查SSL证书相关问题:崩溃日志中涉及WebCoreTestSupport::allowsAnySSLCertificate(),可能与HTTPS证书验证有关。测试环境下可尝试临时允许所有SSL证书(生产环境禁用):
    com.sun.javafx.webkit.WebPage.setWebPreferences("allowAnySSLCertificate", true);
    
  • 升级JavaFX版本:尝试使用JavaFX 22或最新EA版本,查看是否已修复该WebKit native层bug。
  • 启用调试日志:添加VM参数-Djavafx.verbose=true,或启用WebConsole日志,获取重定向过程中的更多细节:
    com.sun.javafx.webkit.WebConsoleListener.setDefaultListener((webView, message, lineNumber, sourceId) -> {
        System.out.printf("WebConsole: [%s:%d] %s%n", sourceId, lineNumber, message);
    });
    
  • 调整运行配置:尝试添加VM参数-Dprism.order=sw切换至软件渲染,排除硬件加速导致的冲突。

内容的提问来源于stack exchange,提问作者tmmls

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 04:57:33