I want to know what is purpose of new URLClassLoader(new URL[0],getClass().getClassLoader());
It means: make a new URLClassloader
that loads classes / resources from an empty array of URLs, and has this classes classloader as the parent.
The resulting classloader object is then discarded.
So I think this is just testing to see if the application is permitted to create a classloader.
The class JVM
is not one that I recognize. I don’t know what that is about.
what happens if this code throw exception
Nothing happens apart from the obvious. If the exception is a SecurityException
you wrap it and throw it as a different exception. Otherwise the exception propagates.
The InsufficientPermissionDetected
class may be a Hudson or Jenkins class. If that is the case, examine the rest of the Hudson or Jenkins codebase to see how it handles the exception.
[how do I] grant permission if it throws
SecurityException
It depends on what platform the code is executed on.
-
If you are running on non-sandboxed Java JVM, you should already have permission … to do everything.
-
If you are running on a sandboxed Java JVM, then the permission must be granted by the sandboxing mechanism. For example, with a trusted JAR file:
- The JAR must be signed with a CERT that the user / user’s JVM trusts.
- The code in the JAR file is then permitted to access controlled APIs as per the policy file that is in force.
For more details, start by reading “Trail: Security Features in Java SE”
-
If you are running on Android …. not sure.
2
solved what this line of code mean….new URLClassLoader(new URL[0],getClass().getClassLoader()); [closed]