-
-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
not fail on getDeclaredXXX when user has used a SecurityManager #79
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1861,7 +1861,12 @@ public static Map getMethods(Class targetClass, boolean staticMethods) | |
} | ||
|
||
private static void collectMethods(Class c, Map result, boolean staticMethods) { | ||
Method[] ma = c.getDeclaredMethods(); | ||
Method[] ma; | ||
try { | ||
ma = c.getDeclaredMethods(); | ||
} catch (SecurityException ignored) { | ||
ma = c.getMethods(); | ||
} | ||
for (int i = 0, icount = ma.length; i < icount; i++) | ||
{ | ||
if (c.isInterface()) | ||
|
@@ -1966,7 +1971,11 @@ public static Map getFields(Class targetClass) | |
Field fa[]; | ||
|
||
result = new HashMap(23); | ||
fa = targetClass.getDeclaredFields(); | ||
try { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And then in the loop here the try..catch code could be replaced by something like:
which limits the overhead of looping over a try..catch when the determination of which mechanism to use is known (someone would have to look at the bytecode to be certain, but a boolean check should be more efficient, especially over multiple iterations). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! I got your idea but they aren't in same scope (method). Their call order isn't guaranteed. Furthermore, I'm not going to use a global flag because user might remove security manager at runtime after some calls. At bottom, according to my googling and experience, java security checks aren't expensive. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @yasserzamani . I know this PR has already been merged, but I wanted to respond to make sure I understood your reply. Ooops ... I missed that the two code blocks were in separate methods, and interpreted them as being in the same block scope with a loop involved. 😥 Since there's not actually any looping over a try..catch involved the new logic shouldn't introduce any noticeable overhead (especially since post-computation results are cached). Thanks for clarifying and pointing out my mis-interpretation. 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool! Frankly I had overlooked the performance. Thanks for your acknowledgement. |
||
fa = targetClass.getDeclaredFields(); | ||
} catch (SecurityException ignored) { | ||
fa = targetClass.getFields(); | ||
} | ||
for (int i = 0; i < fa.length; i++) { | ||
result.put(fa[i].getName(), fa[i]); | ||
} | ||
|
@@ -2264,7 +2273,12 @@ public static List getDeclaredMethods(Class targetClass, String propertyName, bo | |
|
||
private static void collectAccessors(Class c, String baseName, List result, boolean findSets) | ||
{ | ||
final Method[] methods = c.getDeclaredMethods(); | ||
Method[] methods; | ||
try { | ||
methods = c.getDeclaredMethods(); | ||
} catch (SecurityException ignored) { | ||
methods = c.getMethods(); | ||
} | ||
for (int i = 0; i < methods.length; i++) { | ||
if (c.isInterface()) { | ||
if (isDefaultMethod(methods[i])) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there is loop processing involved below, there will probably be extra overhead for processing the try..catch multiple times within the loop. Since we're attempting the getDeclaredMethods vs. getMethods checks here it should be possible to set a boolean flag that determines which methodology the current SecurityManager allows.