OpenJDK / jdk / jdk
changeset 57770:a0c94b292e01
8235739: Rare NPE at WComponentPeer.getGraphics()
Reviewed-by: dmarkov, aivanov
author | serb |
---|---|
date | Fri, 13 Dec 2019 18:39:30 -0800 |
parents | caaebecad412 |
children | d6bfca4cbd97 |
files | src/java.desktop/windows/classes/sun/awt/windows/WComponentPeer.java test/jdk/java/awt/Frame/GetGraphicsStressTest/GetGraphicsStressTest.java |
diffstat | 2 files changed, 20 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/java.desktop/windows/classes/sun/awt/windows/WComponentPeer.java Fri Dec 13 18:37:48 2019 -0800 +++ b/src/java.desktop/windows/classes/sun/awt/windows/WComponentPeer.java Fri Dec 13 18:39:30 2019 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -579,23 +579,25 @@ if (window != null) { final WWindowPeer wpeer = AWTAccessor.getComponentAccessor() .getPeer(window); - Graphics g = wpeer.getTranslucentGraphics(); - // getTranslucentGraphics() returns non-null value for non-opaque windows only - if (g != null) { - // Non-opaque windows do not support heavyweight children. - // Redirect all painting to the Window's Graphics instead. - // The caller is responsible for calling the - // WindowPeer.updateWindow() after painting has finished. - int x = 0, y = 0; - for (Component c = target; c != window; c = c.getParent()) { - x += c.getX(); - y += c.getY(); + if (wpeer != null) { + Graphics g = wpeer.getTranslucentGraphics(); + // getTranslucentGraphics() returns non-null value for non-opaque windows only + if (g != null) { + // Non-opaque windows do not support heavyweight children. + // Redirect all painting to the Window's Graphics instead. + // The caller is responsible for calling the + // WindowPeer.updateWindow() after painting has finished. + int x = 0, y = 0; + for (Component c = target; c != window; c = c.getParent()) { + x += c.getX(); + y += c.getY(); + } + + g.translate(x, y); + g.clipRect(0, 0, target.getWidth(), target.getHeight()); + + return g; } - - g.translate(x, y); - g.clipRect(0, 0, target.getWidth(), target.getHeight()); - - return g; } }
--- a/test/jdk/java/awt/Frame/GetGraphicsStressTest/GetGraphicsStressTest.java Fri Dec 13 18:37:48 2019 -0800 +++ b/test/jdk/java/awt/Frame/GetGraphicsStressTest/GetGraphicsStressTest.java Fri Dec 13 18:39:30 2019 -0800 @@ -27,7 +27,7 @@ /** * @test - * @bug 8235638 + * @bug 8235638 8235739 * @key headful */ public final class GetGraphicsStressTest {