Skip to content

Commit

Permalink
8340849:macos] Crash when creating a child window of a JavaFX window …
Browse files Browse the repository at this point in the history
…after Platform::exit
  • Loading branch information
prsadhuk committed Oct 28, 2024
1 parent 6ac2dd3 commit 858bd97
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.sun.javafx.embed.swing.SwingNodeHelper;
import com.sun.javafx.scene.NodeHelper;
import com.sun.javafx.stage.WindowHelper;
import com.sun.javafx.tk.Toolkit;
import com.sun.javafx.util.Utils;
import java.awt.AWTEvent;
import java.awt.Component;
Expand Down Expand Up @@ -163,9 +164,9 @@ public LightweightContentWrapper createSwingNodeContent(JComponent content, Swin
return new SwingNodeContent(content, node);
}

public DisposerRecord createSwingNodeDisposer(Object frame) {
public DisposerRecord createSwingNodeDisposer(Object frame, SwingNodeInteropN swNodeIOP) {
LightweightFrameWrapper lwFrame = (LightweightFrameWrapper)frame;
return new SwingNodeDisposer(lwFrame);
return new SwingNodeDisposer(lwFrame, swNodeIOP);
}

private static final class OptionalMethod<T> {
Expand Down Expand Up @@ -233,13 +234,24 @@ public void addWindowFocusListener(Object frame, WindowFocusListener l) {

private static class SwingNodeDisposer implements DisposerRecord {
LightweightFrameWrapper lwFrame;
Runnable tkShutdownHook;

SwingNodeDisposer(LightweightFrameWrapper ref) {
SwingNodeDisposer(LightweightFrameWrapper ref, SwingNodeInteropN swNodeIOP) {
this.lwFrame = ref;

// Reset and notify FX stage handle to JLightweightFrame
// so that CPlatformWindow doesn't try to create AWT child window
// once FX is shutdown
final Runnable shutdownHook = () -> {
swNodeIOP.overrideNativeWindowHandle(lwFrame, 0L, null);
};
Toolkit.getToolkit().addShutdownHook(shutdownHook);
tkShutdownHook = shutdownHook;
}

@Override
public void dispose() {
Toolkit.getToolkit().removeShutdownHook(tkShutdownHook);
if (lwFrame != null) {
lwFrame.dispose();
lwFrame = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ private void setContentImpl(JComponent content) {
swNodeIOP.setContent(lwFrame, swNodeIOP.createSwingNodeContent(content, this));
swNodeIOP.setVisible(lwFrame, true);

rec = swNodeIOP.createSwingNodeDisposer(lwFrame);
rec = swNodeIOP.createSwingNodeDisposer(lwFrame, swNodeIOP);
disposerRecRef = Disposer.addRecord(this, rec);

if (getScene() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
import java.util.concurrent.CountDownLatch;
import javax.swing.SwingUtilities;
import javafx.application.Platform;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import test.util.Util;

public class SwingNodePlatformExitCrashTest extends SwingNodeBase {

@Test
@Disabled("JDK-8340849")
public void testPlatformExitBeforeShowHoldEDT() throws InvocationTargetException, InterruptedException {
myApp.createAndShowStage();
CountDownLatch latch = new CountDownLatch(1);
Expand All @@ -51,4 +51,10 @@ public void testPlatformExitBeforeShowHoldEDT() throws InvocationTargetException
runWaitSleep(()-> Platform.exit());
myApp.disposeDialog();
}

@AfterAll
public static void teardownOnce() {
// No-op as Toolkit shutdown is already done in Platform.exit
// and calling superclass teardownOnce will cause hang
}
}

0 comments on commit 858bd97

Please sign in to comment.