why `java.lang.SecurityException: Prohibited package name: java` is required?

前端 未结 8 555
挽巷
挽巷 2020-12-03 16:56

I created a class \"String\" and placed that in package \"java\" [ actually i wanted to create java.lang to see which class is loaded by classLoader as

相关标签:
8条回答
  • 2020-12-03 17:55

    You cannot have "java.*" package names. This is actually hard-coded in the Java core so you cannot even grant a security manager permission to work around it (cf. ClassLoader::preDefineClass(...))

    0 讨论(0)
  • 2020-12-03 17:55

    java is a reserved package name. Only classes inside the JVM can reside in this package.

    If anyone could write in the Java package, that could result in libraries arbitrarily replacing core Java classes by their own implementations. That could result in a lot of thinks, from breaking core Java features to execution of malicious code.

    0 讨论(0)
提交回复
热议问题