summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAssam Boudjelthia <[email protected]>2025-06-27 17:08:46 +0300
committerQt Cherry-pick Bot <[email protected]>2025-06-28 20:54:02 +0000
commitd612b68d23f238115527ad7bf91990e9f496d533 (patch)
treef250fd115857393ffe5ff2a718ea828b2d91dbad
parentbc3500f554b88acc2560ead4e70b603b34cb727a (diff)
Android: fix potential exceptions in Java CursorHandle
Under initOverlay(), obtainStyledAttributes() was using an auto closeable try() block but that's not guaranteed to be implemented on all system, to opt in for manually recycling. Moreover, under width(), m_cursorView is not always guaranteed to be non-null, so guard against that. Pick-to: 6.9 Change-Id: I35bf6d2ecbaf8913c94b070e7d99f72d2030f8b7 Reviewed-by: Ville Voutilainen <[email protected]> (cherry picked from commit d9f10bfaaeef52a5ccfc60c7e75339df39b96ff3) Reviewed-by: Qt Cherry-pick Bot <[email protected]>
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/CursorHandle.java8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/android/jar/src/org/qtproject/qt/android/CursorHandle.java b/src/android/jar/src/org/qtproject/qt/android/CursorHandle.java
index 41256cc64a1..0079135e518 100644
--- a/src/android/jar/src/org/qtproject/qt/android/CursorHandle.java
+++ b/src/android/jar/src/org/qtproject/qt/android/CursorHandle.java
@@ -108,8 +108,11 @@ class CursorHandle implements ViewTreeObserver.OnPreDrawListener
Context context = m_layout.getContext();
int[] attrs = {m_attr};
Drawable drawable;
- try (TypedArray a = context.getTheme().obtainStyledAttributes(attrs)) {
+ TypedArray a = context.getTheme().obtainStyledAttributes(attrs);
+ try {
drawable = a.getDrawable(0);
+ } finally {
+ a.recycle();
}
m_cursorView = new CursorView(context, this);
@@ -189,6 +192,9 @@ class CursorHandle implements ViewTreeObserver.OnPreDrawListener
int width()
{
+ if (m_cursorView == null)
+ return 0;
+
return m_cursorView.getDrawable().getIntrinsicWidth();
}