源码有具体代码,class文件抛出RuntimeException

最近看代码,进入依赖的包的class文件,每个方法只有RuntimeException,如下(mock的):

public class MyServiceContainer {

public static final AppServiceContainer SHARED_CONTAINER;

public MyServiceContainer() {

throw new RuntimeException("com.loserwang.MyServiceContainer was loaded by " + MyServiceContainer.class.getClassLoader() + ", it should be loaded by Pandora Container. Can not load this fake sdk class. please refer to xxxxxx.");

}

public static AppServiceContainer createAppServiceContainer(ApplicationModel var0) {

throw new RuntimeException("com.loserwang.MyServiceContainer was loaded by " + MyServiceContainer.class.getClassLoader() + ", it should be loaded by Pandora Container. Can not load this fake sdk class. please refer to xxxxxx.");

}

public static <T> T getInstance(Class<T> var0) {

throw new RuntimeException("com.loserwang.MyServiceContainer was loaded by " + MyServiceContainer.class.getClassLoader() + ", it should be loaded by Pandora Container. Can not load this fake sdk class. please refer to xxxxxx.");

}

public static <T> List<T> getInstances(Class<T> var0, String... var1) {

throw new RuntimeException("com.loserwang.MyServiceContainer was loaded by " + MyServiceContainer.class.getClassLoader() + ", it should be loaded by Pandora Container. Can not load this fake sdk class. please refer to xxxxxx."");

}

然后下载source文件:

public class MyServiceContainer {

public static final AppServiceContainer SHARED_CONTAINER;

public MyServiceContainer() {

super();

}

public static AppServiceContainer createAppServiceContainer(ApplicationModel var0) {

// 具体逻辑代码

}

public static <T> T getInstance(Class<T> var0) {

// 具体逻辑代码

}

public static <T> List<T> getInstances(Class<T> var0, String... var1) {

// 具体逻辑代码

}

既然class文件是通过java文件编译的,为什么会有如此大的区别呢?

补充:


回答:

淦,我搞明白了。maven下载jar包中的class文件并不是由源代码编译而成,而是一个fake sdk class,写代码和编译时不会报错。但是运行时就会报错。
必须使用公司的容器来加载。该容器中有自定义的类加载器,不会加载该fake class,而是会加载内置的class(由源代码编译而成)。
有点类似接口或者spi了。


回答:

不清楚这个库是干嘛的
目测一个版本是用在本地环境用来通过编译的,因为本地无法正常运行所以都抛异常
另一个是用在运行环境用来运行的


回答:

Maven?默认只显示桩代码(Stub),也就是只有接口定义、没有具体实现,想看实现就需要下载 sources。

目的是为了加快访问速度,大部分场景下不需要那么一大坨的源码,只需要看定义。另外某种程度上也算是保密了,如果包的提供方没上传 sources 文件的话就“相当于”闭源了。

以上是 源码有具体代码,class文件抛出RuntimeException 的全部内容, 来源链接: utcz.com/p/944088.html

回到顶部