RFR: 8370141: [macOS] Crash after PrinterJob ends when Graphics.create() is used.
Sergey Bylokhov
serb at openjdk.org
Tue Oct 21 21:42:02 UTC 2025
On Tue, 21 Oct 2025 20:50:17 GMT, Phil Race <prr at openjdk.org> wrote:
>> I meant, is it possible to get this surfaceData before invalidation on one thread, start rendering to it, and then call delegate.dispose() on another thread? Don't we need some kind of synchronization or is it already somehow implemented?
>
> delegate.dispose just replaces the reference in the graphics with a NullSurfaceData.
> There's no synchronization needed.
multi-threaded version of the `PrintJobAfterEndTest` always crashed for me even with a patch:
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.JobAttributes;
import java.awt.JobAttributes.DialogType;
import java.awt.PageAttributes;
import java.awt.PrintJob;
import java.awt.Toolkit;
import java.util.concurrent.CountDownLatch;
public final class MTPrintJobAfterEndTest {
public static void main(String[] args) throws InterruptedException {
JobAttributes jobAttributes = new JobAttributes();
jobAttributes.setDialog(DialogType.NONE);
PageAttributes pageAttributes = new PageAttributes();
Frame f = new Frame();
Toolkit toolkit = f.getToolkit();
for (int i = 0; i < 1000; i++) {
PrintJob job = toolkit.getPrintJob(f, "Crash Test",jobAttributes,
pageAttributes);
if (job != null) {
Graphics g = job.getGraphics();
CountDownLatch latch = new CountDownLatch(1);
Thread endThread = new Thread(() -> {
try {
latch.await();
job.end();
} catch (Throwable ignore) {}
});
Thread drawThread = new Thread(() -> {
try {
latch.await();
g.drawLine(0, 100, 200, 100);
} catch (Throwable ignore) {}
});
endThread.start();
drawThread.start();
latch.countDown();
endThread.join();
drawThread.join();
}
}
}
}
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27905#discussion_r2449772224
More information about the client-libs-dev
mailing list