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-29 09:49:15 +0000
commit220811b53710f0c42e37e671bc0fba54f66e5d11 (patch)
treeba4f6aae1f51ca5a0b0160dc0ea3472ac66232f4
parent7854a7d74fe77eda51692c1a507bb5f0f263cd2d (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. Change-Id: I35bf6d2ecbaf8913c94b070e7d99f72d2030f8b7 Reviewed-by: Ville Voutilainen <[email protected]> (cherry picked from commit d9f10bfaaeef52a5ccfc60c7e75339df39b96ff3) Reviewed-by: Qt Cherry-pick Bot <[email protected]> (cherry picked from commit d612b68d23f238115527ad7bf91990e9f496d533)
-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();
}