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

显示FileChooser对话框时出现CATransaction相关日志的问题咨询

问题描述

在IntelliJ Community Edition 2021.2中运行JavaFX程序时,弹出FileChooser对话框后,控制台会输出日志:

java[934:22850] +[CATransaction synchronize] called within transaction

对话框功能正常,但对该日志的含义和是否需要处理存在疑问。

环境信息

  • MacOS 13.0.1 (Ventura)
  • IntelliJ Community Edition 2021.2
  • JDK 15.0.2
  • JavaFX 15.0.1+1

测试代码

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.stage.FileChooser;
import javafx.stage.Stage;

import java.io.*;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) {
        FileChooser myChooser = new FileChooser();

        primaryStage.setOnCloseRequest(e -> {
            e.consume();
            primaryStage.close();
        });

        VBox root = new VBox(5);
        Scene mainScene = new Scene(root, 650, 300);

        Button websiteSupportButton = new Button("Process file");
        websiteSupportButton.setMinWidth(150);
        root.getChildren().add(websiteSupportButton);
        websiteSupportButton.setOnAction(e -> processFiles(primaryStage, myChooser));

        primaryStage.setX(20);
        primaryStage.setY(20);
        primaryStage.setScene(mainScene);
        primaryStage.setTitle("Error test");
        primaryStage.show();
    }

    private static void processFiles(Stage myStage, FileChooser myChooser) {
        File inputFile = myChooser.showOpenDialog(myStage);
        if (inputFile != null) {
            System.out.println(" file processed");
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}
问题解析与处理方案
  • 该日志并非程序错误,是MacOS Core Animation框架的内部提示信息。JavaFX的FileChooser在MacOS上会调用原生的文件选择面板(NSOpenPanel),Ventura系统的Core Animation在处理这类跨框架调用时,会触发事务同步的提示,完全不影响程序功能。
  • 核心原因是你使用的JavaFX 15版本发布早于MacOS Ventura,对该系统的兼容性适配不足。后续JavaFX的LTS版本(如17、21)已经修复了这类冗余日志的输出问题。
  • 处理建议:
    1. 优先升级版本:将JavaFX升级到17及以上的LTS版本,同时配套升级JDK到对应兼容版本(如JDK 17),这是最彻底的解决方式。
    2. 临时过滤日志:如果暂时无法升级,可通过JVM参数过滤该日志。在IntelliJ的运行配置中添加VM选项:
      -Djava.util.logging.config.file=logging.properties
      
      然后在项目根目录创建logging.properties文件,添加配置:
      com.sun.javafx.application.PlatformImpl.level=SEVERE
      
      这样可以屏蔽掉这类非严重级别的日志输出。
    3. 忽略日志:如果不介意控制台的冗余输出,可直接忽略该日志,因为它不会影响程序的正常运行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 16:35:14