Skip to content

Commit f807fbf

Browse files
mkartashevjbrbot
authored andcommitted
JBR-9730 Wayland: to add a secondary expression in assertions
1 parent 12aa1d1 commit f807fbf

19 files changed

+124
-119
lines changed

src/java.desktop/unix/classes/sun/awt/wl/FullFrameDecorationHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public final void markRepaintNeeded(boolean value) {
164164

165165
@Override
166166
public void paint(Graphics g) {
167-
assert isRepaintNeeded();
167+
assert isRepaintNeeded() : "paint() called when no repaint needed";
168168

169169
int width = peer.getWidth();
170170
int height = peer.getHeight();
@@ -196,7 +196,7 @@ private static MouseEvent convertEvent(MouseEvent e, int newId) {
196196
}
197197

198198
private boolean isSignificantDrag(Point p) {
199-
assert EventQueue.isDispatchThread();
199+
assert EventQueue.isDispatchThread() : "Method must only be invoked on EDT";
200200

201201
Objects.requireNonNull(p);
202202
return pressedLocation != null && isSignificantDragDistance(pressedLocation, p);
@@ -208,7 +208,7 @@ private boolean isSignificantDrag(Point p) {
208208

209209
@Override
210210
boolean processMouseEvent(MouseEvent e) {
211-
assert EventQueue.isDispatchThread();
211+
assert EventQueue.isDispatchThread() : "Method must only be invoked on EDT";
212212

213213
if (super.processMouseEvent(e)) return true;
214214

@@ -326,7 +326,7 @@ private boolean reset() {
326326
}
327327

328328
private boolean processMouseEvent(MouseEvent e) {
329-
assert EventQueue.isDispatchThread();
329+
assert EventQueue.isDispatchThread() : "Method must only be invoked on EDT";
330330

331331
Rectangle buttonBounds = bounds.get();
332332
boolean ourLocation = buttonBounds != null && e.getID() != MouseEvent.MOUSE_EXITED &&

src/java.desktop/unix/classes/sun/awt/wl/GtkFrameDecoration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class GtkFrameDecoration extends FullFrameDecorationHelper {
6868
public GtkFrameDecoration(WLDecoratedPeer peer, boolean showMinimize, boolean showMaximize) {
6969
super(peer, showMinimize, showMaximize);
7070
nativePtr = nativeCreateDecoration(showMinimize, showMaximize, isDarkTheme());
71-
assert nativePtr != 0;
71+
assert nativePtr != 0 : "Failed to create the native part of the decoration";
7272
int t = nativeGetIntProperty(nativePtr, "gtk-dnd-drag-threshold");
7373
dndThreshold = t > 0 ? t : 4;
7474
}
@@ -87,8 +87,8 @@ protected void paintTitleBar(Graphics2D g2d) {
8787
int width = peer.getWidth();
8888
int height = titleBarHeight;
8989

90-
assert width >= titleBarMinWidth;
91-
assert peer.getHeight() >= titleBarHeight;
90+
assert width >= titleBarMinWidth : "The frame width is too small to display the title bar";
91+
assert peer.getHeight() >= titleBarHeight : "The frame height is too small to display the title bar";
9292

9393
double scale = ((WLGraphicsConfig) peer.getGraphicsConfiguration()).getEffectiveScale();
9494
g2d.setBackground(new Color(0, true));

src/java.desktop/unix/classes/sun/awt/wl/ServerSideFrameDecoration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void notifyNativeWindowToBeHidden(long nativePtr) {
9696
@Override
9797
public void dispose() {
9898
// Native resources must have been already disposed when the window was hidden
99-
assert nativeDecorPtr == 0;
99+
assert nativeDecorPtr == 0 : "Native resources must have been already disposed";
100100
}
101101

102102
private native long createToplevelDecorationImpl(long nativeFramePtr);

src/java.desktop/unix/classes/sun/awt/wl/WLComponentPeer.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ static void moveToOverlap(Rectangle what, Rectangle where) {
320320
if (what.getMinY() >= where.getMaxY()) {
321321
what.y -= what.getMinY() - where.getMaxY();
322322
}
323-
assert what.intersects(where);
323+
assert what.intersects(where) : String.format("Failed to move %s to overlap %s", what, where);
324324
}
325325

326326
Point nativeLocationForPopup(Window popup, Component popupParent, Window toplevel) {
@@ -387,7 +387,7 @@ protected void wlSetVisible(boolean v) {
387387
boolean isUnconstrained = isPopupPositionUnconstrained();
388388

389389
performLocked(() -> {
390-
assert wlSurface == null;
390+
assert wlSurface == null : "Invisible window already has a Wayland surface attached";
391391
wlSurface = new WLMainSurface((WLWindowPeer) this);
392392
long wlSurfacePtr = wlSurface.getWlSurfacePtr();
393393
if (isWlPopup) {
@@ -477,7 +477,7 @@ public boolean isResizable() {
477477

478478
@Override
479479
public void updateSurfaceSize() {
480-
assert SunToolkit.isAWTLockHeldByCurrentThread();
480+
assert SunToolkit.isAWTLockHeldByCurrentThread() : "This method must be invoked while holding the AWT lock";
481481
// Note: must be called after a buffer of proper size has been attached to the surface,
482482
// but the surface has not yet been committed. Otherwise, the sizes will get out of sync,
483483
// which may result in visual artifacts.
@@ -910,7 +910,7 @@ void showWindowMenu(long serial, int x, int y) {
910910
// a button press, key press, or touch down event."
911911
// So 'serial' must appertain to such an event.
912912

913-
assert serial != 0;
913+
assert serial != 0 : "The serial number of the event requesting the window menu must be non-zero";
914914

915915
int xNative = javaUnitsToSurfaceUnits(x);
916916
int yNative = javaUnitsToSurfaceUnits(y);
@@ -970,7 +970,7 @@ public void dispose() {
970970
WLToolkit.targetDisposedPeer(target, this);
971971

972972
performLocked(() -> {
973-
assert !isVisible();
973+
assert !isVisible() : "Disposed window must have been already hidden";
974974

975975
nativeDisposeFrame(nativePtr);
976976
nativePtr = 0;
@@ -1373,7 +1373,8 @@ void dispatchPointerEventInContext(WLPointerEvent e, WLInputState oldInputState,
13731373
}
13741374

13751375
if (verticalMWERoundRotations != 0 || verticalMWEPreciseRotations != 0) {
1376-
assert(verticalMWEScrollAmount > 0);
1376+
assert verticalMWEScrollAmount > 0
1377+
: String.format("Vertical scrolling event has negative scroll amount: %d", verticalMWEScrollAmount);
13771378

13781379
final MouseEvent mouseEvent = new MouseWheelEvent(getTarget(),
13791380
MouseEvent.MOUSE_WHEEL,
@@ -1392,7 +1393,8 @@ void dispatchPointerEventInContext(WLPointerEvent e, WLInputState oldInputState,
13921393
}
13931394

13941395
if (horizontalMWERoundRotations != 0 || horizontalMWEPreciseRotations != 0) {
1395-
assert(horizontalMWEScrollAmount > 0);
1396+
assert horizontalMWEScrollAmount > 0
1397+
: String.format("Horizontal scrolling event has negative scroll amount: %d", horizontalMWEScrollAmount);;
13961398

13971399
final MouseEvent mouseEvent = new MouseWheelEvent(getTarget(),
13981400
MouseEvent.MOUSE_WHEEL,
@@ -1603,7 +1605,7 @@ void startDrag(long serial) {
16031605
// "This request must be used in response to some sort of user action like a button press,
16041606
// key press, or touch down event. The passed serial is used to determine the type
16051607
// of interactive move (touch, pointer, etc)."
1606-
assert serial != 0;
1608+
assert serial != 0 : "The serial number of the event requesting the drag must be non-zero";
16071609

16081610
performLocked(() -> nativeStartDrag(serial, nativePtr));
16091611
}
@@ -1612,7 +1614,7 @@ void startResize(long serial, int edges) {
16121614
// "This request must be used in response to some sort of user action like a button press,
16131615
// key press, or touch down event. The passed serial is used to determine the type
16141616
// of interactive resize (touch, pointer, etc)."
1615-
assert serial != 0;
1617+
assert serial != 0 : "The serial number of the event requesting the resize must be non-zero";
16161618

16171619
performLocked(() -> nativeStartResize(serial, nativePtr, edges));
16181620
}
@@ -1692,7 +1694,7 @@ Point convertPontFromDeviceSpace(int x, int y) {
16921694

16931695
void notifyConfigured(int newSurfaceX, int newSurfaceY, int newSurfaceWidth, int newSurfaceHeight,
16941696
boolean active, boolean maximized, boolean fullscreen) {
1695-
assert SunToolkit.isAWTLockHeldByCurrentThread();
1697+
assert SunToolkit.isAWTLockHeldByCurrentThread() : "This method must be invoked while holding the AWT lock";
16961698

16971699
// NB: The width and height, as well as X and Y arguments, specify the size and the location
16981700
// of the window in surface-local coordinates.
@@ -1773,12 +1775,12 @@ void notifyEnteredOutput(int wlOutputID) {
17731775
}
17741776

17751777
void notifyPopupDone() {
1776-
assert(targetIsWlPopup());
1778+
assert targetIsWlPopup() : "This method must be invoked only for popups";
17771779
target.setVisible(false);
17781780
}
17791781

17801782
void checkIfOnNewScreen() {
1781-
assert SunToolkit.isAWTLockHeldByCurrentThread();
1783+
assert SunToolkit.isAWTLockHeldByCurrentThread() : "This method must be invoked while holding the AWT lock";
17821784

17831785
if (wlSurface == null) return;
17841786
final WLGraphicsDevice newDevice = wlSurface.getGraphicsDevice();
@@ -2023,7 +2025,7 @@ public int getSize() {
20232025

20242026
@Override
20252027
public void updateSurfaceSize() {
2026-
assert SunToolkit.isAWTLockHeldByCurrentThread();
2028+
assert SunToolkit.isAWTLockHeldByCurrentThread() : "This method must be invoked while holding the AWT lock";
20272029

20282030
shadowSurface.updateSurfaceSize(shadowWlSize.getSurfaceWidth(), shadowWlSize.getSurfaceHeight());
20292031
}
@@ -2035,22 +2037,22 @@ public void resizeToParentWindow() {
20352037
}
20362038

20372039
public void createSurface() {
2038-
assert shadowSurface == null;
2039-
assert SunToolkit.isAWTLockHeldByCurrentThread();
2040+
assert shadowSurface == null : "The shadow surface must not be created twice";
2041+
assert SunToolkit.isAWTLockHeldByCurrentThread() : "This method must be invoked while holding the AWT lock";
20402042

20412043
int shadowOffset = -javaUnitsToSurfaceUnits(shadowSize);
20422044
shadowSurface = new WLSubSurface(wlSurface, shadowOffset, shadowOffset);
20432045
}
20442046

20452047
public void commitSurface() {
20462048
assert shadowSurface != null;
2047-
assert SunToolkit.isAWTLockHeldByCurrentThread();
2049+
assert SunToolkit.isAWTLockHeldByCurrentThread() : "This method must be invoked while holding the AWT lock";
20482050

20492051
shadowSurface.commit();
20502052
}
20512053

20522054
public void dispose() {
2053-
assert SunToolkit.isAWTLockHeldByCurrentThread();
2055+
assert SunToolkit.isAWTLockHeldByCurrentThread() : "This method must be invoked while holding the AWT lock";
20542056

20552057
if (shadowSurface != null) {
20562058
shadowSurface.dispose();
@@ -2065,7 +2067,7 @@ public void dispose() {
20652067
}
20662068

20672069
public void hide() {
2068-
assert SunToolkit.isAWTLockHeldByCurrentThread();
2070+
assert SunToolkit.isAWTLockHeldByCurrentThread() : "This method must be invoked while holding the AWT lock";
20692071

20702072
if (shadowSurface != null) {
20712073
shadowSurface.dispose();
@@ -2074,15 +2076,15 @@ public void hide() {
20742076
}
20752077

20762078
public void updateSurfaceData() {
2077-
assert SunToolkit.isAWTLockHeldByCurrentThread();
2079+
assert SunToolkit.isAWTLockHeldByCurrentThread() : "This method must be invoked while holding the AWT lock";
20782080

20792081
needsRepaint = true;
20802082
SurfaceData.convertTo(WLSurfaceDataExt.class, shadowSurfaceData).revalidate(
20812083
getGraphicsConfiguration(), shadowWlSize.getPixelWidth(), shadowWlSize.getPixelHeight(), getDisplayScale());
20822084
}
20832085

20842086
public void paint() {
2085-
assert SunToolkit.isAWTLockHeldByCurrentThread();
2087+
assert SunToolkit.isAWTLockHeldByCurrentThread() : "This method must be invoked while holding the AWT lock";
20862088

20872089
if (!needsRepaint) {
20882090
return;
@@ -2108,7 +2110,7 @@ public void commitSurfaceData() {
21082110

21092111
public void notifyConfigured(boolean active, boolean maximized, boolean fullscreen) {
21102112
assert shadowSurface != null;
2111-
assert SunToolkit.isAWTLockHeldByCurrentThread();
2113+
assert SunToolkit.isAWTLockHeldByCurrentThread() : "This method must be invoked while holding the AWT lock";
21122114

21132115
needsRepaint |= active ^ isActive;
21142116

src/java.desktop/unix/classes/sun/awt/wl/WLDataOffer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public synchronized byte[] receiveData(String mime) throws IOException {
7777

7878
fd = openReceivePipe(nativePtr, mime);
7979

80-
assert(fd != -1); // Otherwise an exception should be thrown from native code
80+
// Otherwise an exception should be thrown from native code
81+
assert fd != -1 : "An invalid file descriptor received from the native code";
8182

8283
FileDescriptor javaFD = new FileDescriptor();
8384
jdk.internal.access.SharedSecrets.getJavaIOFileDescriptorAccess().set(javaFD, fd);

src/java.desktop/unix/classes/sun/awt/wl/WLDataSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class WLDataSource {
5353
var wlDataTransferer = (WLDataTransferer) WLDataTransferer.getInstance();
5454

5555
nativePtr = initNative(dataDevice.getNativePtr(), protocol);
56-
assert nativePtr != 0; // should've already thrown in native
56+
assert nativePtr != 0 : "Failed to initialize the native part of the source"; // should've already thrown in native
5757
this.data = data;
5858

5959
try {

src/java.desktop/unix/classes/sun/awt/wl/WLGraphicsDevice.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ private WLGraphicsDevice(int id,
128128
int widthLogical, int heightLogical,
129129
int widthMm, int heightMm,
130130
int displayScale) {
131-
assert width > 0 && height > 0;
132-
assert widthLogical > 0 && heightLogical > 0;
133-
assert widthMm > 0 && heightMm > 0;
134-
assert displayScale > 0;
131+
assert width > 0 && height > 0 : String.format("Invalid device size: %dx%d", width, height);
132+
assert widthLogical > 0 && heightLogical > 0 : String.format("Invalid logical device size: %dx%d", widthLogical, heightLogical);
133+
assert widthMm > 0 && heightMm > 0 : String.format("Invalid physical device size: %dx%d", widthMm, heightMm);
134+
assert displayScale > 0 : String.format("Invalid display scale: %d", displayScale);
135135

136136
this.wlID = id;
137137
this.name = name;
@@ -176,10 +176,10 @@ void updateConfiguration(String name,
176176
int widthLogical, int heightLogical,
177177
int widthMm, int heightMm,
178178
int scale) {
179-
assert width > 0 && height > 0;
180-
assert widthLogical > 0 && heightLogical > 0;
181-
assert widthMm > 0 && heightMm > 0;
182-
assert scale > 0;
179+
assert width > 0 && height > 0 : String.format("Invalid device size: %dx%d", width, height);
180+
assert widthLogical > 0 && heightLogical > 0 : String.format("Invalid logical device size: %dx%d", widthLogical, heightLogical);
181+
assert widthMm > 0 && heightMm > 0 : String.format("Invalid physical device size: %dx%d", widthMm, heightMm);
182+
assert scale > 0 : String.format("Invalid display scale: %d", scale);
183183

184184
this.name = name;
185185
this.x = x;

src/java.desktop/unix/classes/sun/awt/wl/WLInputState.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ private PointerButtonEvent getNewPointerButtonEvent(WLPointerEvent pointerEvent,
242242
WLPointerEvent newEventWithTimestamp,
243243
WLPointerEvent newEventWithPosition) {
244244
if (pointerEvent.hasButtonEvent() && pointerEvent.getIsButtonPressed() && newEventWithSurface != null) {
245-
assert newEventWithTimestamp != null && newEventWithPosition != null;
245+
assert newEventWithTimestamp != null && newEventWithPosition != null
246+
: "Events with timestamp and position are both required to be present";
247+
246248
int clickCount = 1;
247249
final boolean pressedSameButton = pointerButtonPressedEvent != null
248250
&& pointerEvent.getButtonCode() == pointerButtonPressedEvent.linuxCode;

src/java.desktop/unix/classes/sun/awt/wl/WLKeyboard.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private class KeyRepeatManager {
4848
// called from native code
4949
void setRepeatInfo(int charsPerSecond, int delayMillis) {
5050
// this function receives (0, 0) when key repeat is disabled
51-
assert EventQueue.isDispatchThread();
51+
assert EventQueue.isDispatchThread() : "Method must only be invoked on EDT";
5252
this.delayBeforeRepeatMillis = delayMillis;
5353
if (charsPerSecond > 0) {
5454
this.delayBetweenRepeatMillis = (int) (1000.0 / charsPerSecond);
@@ -64,7 +64,7 @@ boolean isRepeatEnabled() {
6464
}
6565

6666
void cancelRepeat() {
67-
assert EventQueue.isDispatchThread();
67+
assert EventQueue.isDispatchThread() : "Method must only be invoked on EDT";
6868
if (currentRepeatTask != null) {
6969
currentRepeatTask.cancel();
7070
currentRepeatTask = null;
@@ -74,15 +74,15 @@ void cancelRepeat() {
7474

7575
// called from native code
7676
void stopRepeat(int keycode) {
77-
assert EventQueue.isDispatchThread();
77+
assert EventQueue.isDispatchThread() : "Method must only be invoked on EDT";
7878
if (currentRepeatKeycode == keycode) {
7979
cancelRepeat();
8080
}
8181
}
8282

8383
// called from native code
8484
void startRepeat(long serial, long timestamp, int keycode) {
85-
assert EventQueue.isDispatchThread();
85+
assert EventQueue.isDispatchThread() : "Method must only be invoked on EDT";
8686
cancelRepeat();
8787
if (keycode == 0 || !isRepeatEnabled()) {
8888
return;
@@ -123,7 +123,7 @@ public void run() {
123123
public native boolean isNumLockPressed();
124124

125125
public void onLostFocus() {
126-
assert EventQueue.isDispatchThread();
126+
assert EventQueue.isDispatchThread() : "Method must only be invoked on EDT";
127127
keyRepeatManager.cancelRepeat();
128128
cancelCompose();
129129
}

src/java.desktop/unix/classes/sun/awt/wl/WLMainSurface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void notifyLeftOutput(int wlOutputID) {
9191
}
9292

9393
public void activateByAnotherSurface(long serial, long activatingSurfacePtr) {
94-
assert SunToolkit.isAWTLockHeldByCurrentThread();
94+
assert SunToolkit.isAWTLockHeldByCurrentThread() : "This method must be invoked while holding the AWT lock";
9595
assertIsValid();
9696

9797
nativeActivate(getNativePtr(), serial, activatingSurfacePtr);

0 commit comments

Comments
 (0)