From d53e563e15426ce27a4122f65fe968ef7fd808ea Mon Sep 17 00:00:00 2001 From: Greg Brail Date: Wed, 17 Jul 2024 16:24:33 -0700 Subject: [PATCH] Address two more deprecations --- .../main/java/org/mozilla/javascript/JavaMembers.java | 5 ++--- .../org/mozilla/javascript/jdk18/VMBridge_jdk18.java | 10 +--------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/rhino/src/main/java/org/mozilla/javascript/JavaMembers.java b/rhino/src/main/java/org/mozilla/javascript/JavaMembers.java index c034467ed8..e315a049b4 100644 --- a/rhino/src/main/java/org/mozilla/javascript/JavaMembers.java +++ b/rhino/src/main/java/org/mozilla/javascript/JavaMembers.java @@ -328,8 +328,7 @@ private void discoverAccessibleMethods( if (isPublic(mods) || isProtected(mods) || includePrivate) { MethodSignature sig = new MethodSignature(method); if (!map.containsKey(sig)) { - if (includePrivate && !method.isAccessible()) - method.setAccessible(true); + if (includePrivate) method.trySetAccessible(); map.put(sig, method); } } @@ -667,7 +666,7 @@ private Field[] getAccessibleFields(boolean includeProtected, boolean includePri for (Field field : declared) { int mod = field.getModifiers(); if (includePrivate || isPublic(mod) || isProtected(mod)) { - if (!field.isAccessible()) field.setAccessible(true); + field.trySetAccessible(); fieldsList.add(field); } } diff --git a/rhino/src/main/java/org/mozilla/javascript/jdk18/VMBridge_jdk18.java b/rhino/src/main/java/org/mozilla/javascript/jdk18/VMBridge_jdk18.java index 51aa64f19e..d006cd8c62 100644 --- a/rhino/src/main/java/org/mozilla/javascript/jdk18/VMBridge_jdk18.java +++ b/rhino/src/main/java/org/mozilla/javascript/jdk18/VMBridge_jdk18.java @@ -54,15 +54,7 @@ protected void setContext(Object contextHelper, Context cx) { @Override protected boolean tryToMakeAccessible(AccessibleObject accessible) { - if (accessible.isAccessible()) { - return true; - } - try { - accessible.setAccessible(true); - } catch (Exception ex) { - } - - return accessible.isAccessible(); + return accessible.trySetAccessible(); } @Override