JBR-3813 Regression after fix for JBR-3688

1. Cached bounds and insets must be cloned before return because they
aren't immutable objects.
2. Fixed the deadlock in resetBoundsCache() by synchronizing on a dedicated
lock.

(cherry picked from commit cd5314db8b)
This commit is contained in:
Maxim Kartashev
2021-09-27 00:30:17 -07:00
committed by jbrbot
parent e8c37b471a
commit bc957c83b7
2 changed files with 13 additions and 8 deletions

View File

@@ -1190,7 +1190,7 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
@Override
public Insets getScreenInsets(final GraphicsConfiguration gc) {
if (useCachedInsets) {
return cachedInsets.computeIfAbsent(gc, this::getScreenInsetsImpl);
return (Insets)cachedInsets.computeIfAbsent(gc, this::getScreenInsetsImpl).clone();
} else {
return getScreenInsetsImpl(gc);
}

View File

@@ -149,21 +149,26 @@ public final class X11GraphicsDevice extends GraphicsDevice
}
private Rectangle boundsCached;
private final Object boundsCacheLock = new Object();
private synchronized Rectangle getBoundsCached() {
if (boundsCached == null) {
boundsCached = getBoundsImpl();
private Rectangle getBoundsCached() {
synchronized (boundsCacheLock) {
if (boundsCached == null) {
boundsCached = getBoundsImpl();
}
return boundsCached;
}
return boundsCached;
}
public synchronized void resetBoundsCache() {
boundsCached = null;
public void resetBoundsCache() {
synchronized (boundsCacheLock) {
boundsCached = null;
}
}
public Rectangle getBounds() {
if (X11GraphicsEnvironment.useBoundsCache()) {
return getBoundsCached();
return new Rectangle(getBoundsCached());
}
else {
return getBoundsImpl();