为什么`java.lang.SecurityException:禁止包名:java`是必需的? [英] why `java.lang.SecurityException: Prohibited package name: java` is required?
问题描述
我创建了一个类String并将其放在包java中[实际上我想创建 java.lang 以查看classLoader加载哪个类
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
一旦将类加载到JVM中,
相同的类(我重复,同一个类)
将不再被加载
Once a class is loaded into a JVM, the same class (I repeat, the same class) will not be loaded again
引自oreilly]。但是之后的事情,为什么运行这个类我得到了?
java.lang.SecurityException:禁止的包名: java
quoted from oreilly ] . But that thing later, why on running this class i am getting
java.lang.SecurityException: Prohibited package name: java
为什么安全性原因java不允许我在 java 包中有一个类?如果不进行此类检查,可以做什么?
For which security reason java is not allowing me to have a class in java package? What one could do if there will not be no such check?
推荐答案
用户代码从不允许将类放入其中一个标准Java包中。这样,用户代码就无法访问Java实现中的任何包私有类/方法/字段。其中一些包私有对象允许访问JVM内部。 (我特别想到 SharedSecrets
。)
User code is never allowed to put classes into one of the standard Java packages. That way, user code cannot access any package-private classes/methods/fields in the Java implementation. Some of those package-private objects allow access to JVM internals. (I'm thinking of SharedSecrets
in particular.)
这篇关于为什么`java.lang.SecurityException:禁止包名:java`是必需的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!