简体   繁体   English

resolveClass 不解析符号引用

[英]resolveClass doesn't resolve symbolic references

JLS says that resolveClass method should verify all symbolic links JLS 说 resolveClass 方法应该验证所有符号链接

This specification allows an implementation flexibility as to when linking activities (and, because of recursion, loading) take place, provided that the semantics of the Java programming language are respected, that a class or interface is completely verified and prepared before it is initialized, and that errors detected during linkage are thrown at a point in the program where some action is taken by the program that might require linkage to the class or interface involved in the error.该规范允许在何时发生链接活动(以及由于递归,加载)时实现灵活性,前提是 Java 编程语言的语义得到尊重,class 或接口在初始化之前经过完全验证和准备,并且在链接过程中检测到的错误会在程序中的某个点引发,程序在该点采取可能需要链接到 class 或涉及错误的接口的操作。

So I tried to create class T that references another class in the first project and created the second project with a custom class loader loads class T but not load another referenced class. So I tried to create class T that references another class in the first project and created the second project with a custom class loader loads class T but not load another referenced class.

public class T {
    public static AnotherClass field = new AnotherClass();
}
public class AnonClassLoader extends ClassLoader {

    public Class findClass(String str) {
        byte[] bytes = new byte[0];
        try {
            bytes = Files.readAllBytes(Paths.get(str));
        } catch (IOException e) {
            e.printStackTrace();
        }
        Class<?> aClass = defineClass(null, bytes, 0, bytes.length);
        return aClass;
    }

    public static void main(String[] args) throws IOException, NoSuchMethodException, IllegalAccessException,
        InvocationTargetException, InstantiationException, ClassNotFoundException {
        AnonClassLoader anonClassLoader = new AnonClassLoader();
        Class<?> aClass = anonClassLoader.loadClass("/Users/root/IdeaProjects/untitled/T.class", true);
        System.out.println(aClass.getName());
    }
}

So I expect to get NoClassDefFound as soon as possible, but the actual result - no errors are thrown, class resolved successfully所以我希望尽快得到NoClassDefFound,但实际结果——没有抛出任何错误,class成功解决

So, according to Bug ID: JDK-8057777 Cleanup of old and unused VM interfaces there is no static resolving in the hotspot.因此,根据错误 ID: JDK-8057777 Cleanup of old and used VM interfaces ,热点中没有 static 解析。

Meanwhile, in hotspot jdk 8 native function has no implementation同时,在hotspot jdk 8 native function中没有实现

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM