首先我的项目由Tomcat7升级为tomcat8(8.8.100)
本地代码运行没问题,放到测试服务器运行也没问题
但是放到云服务器上就出现问题了
附件上传报错
java.lang.SecurityException: class "org.apache.commons.io.output.ByteArrayOutputStream"'s signer information does not match signer information of other classes in the same package
报错的意思是:签名者信息与同一包中其他类的签名者信息不匹配
一开始放到生产测试功能的时候才发现这个问题,其他功能测试下来都没问题就这个附件上传有这个情况。
我看源码commons.io自己的一个类new了ByteArrayOutputStream,懵逼。
commons-io-2.5.jar
private DeferredFileOutputStream(int threshold, File outputFile, String prefix, String suffix, File directory) {
super(threshold);
this.closed = false;
this.outputFile = outputFile;
this.memoryOutputStream = new ByteArrayOutputStream();
this.currentOutputStream = this.memoryOutputStream;
this.prefix = prefix;
this.suffix = suffix;
this.directory = directory;
}
commons-io-2.6.jar
private DeferredFileOutputStream(int threshold, File outputFile, String prefix, String suffix, File directory, int initialBufferSize) { super(threshold); this.closed = false; this.outputFile = outputFile; this.prefix = prefix; this.suffix = suffix; this.directory = directory; this.memoryOutputStream = new ByteArrayOutputStream(initialBufferSize); this.currentOutputStream = this.memoryOutputStream; }
生产:java version "1.8.0_281",tomcat8.5.100 commons-io-2.5.jar(异常)
自己的阿里云服务器:java version "1.8.0_202",tomcat8.5.100 commons-io-2.5.jar(异常)
commons-io-2.6.jar(无异常)
测服: java version "1.8.0_281",tomcat8.5.100 commons-io-2.5.jar(无异常)
本地电脑:java version "1.8.0_341",tomcat8.5.100 commons-io-2.5.jar(无异常)
总的来说问题很奇怪可能是云服务器启动tomcat走的类加载器不同,导致安全策略规则不一样。
查看jvm的安全策略文件其实上面几个版本的安全策略文件都是一模一样的,官方没有修改过。
还有一点就是commons-io-2.5.jar一定是有点毛病在身上的。
虽然问题解决了,但是没有完全发现这个问题的具体原因,有没有大佬指点一下。
报错信息
java.lang.SecurityException: class "org.apache.commons.io.output.ByteArrayOutputStream"'s signer information does not match signer information of other classes in the same package
at java.lang.ClassLoader.checkCerts(ClassLoader.java:891)
at java.lang.ClassLoader.preDefineClass(ClassLoader.java:661)
at java.lang.ClassLoader.defineClass(ClassLoader.java:754)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2344)
at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:817)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1302)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1150)
at org.apache.commons.fileupload.disk.DiskFileItem.getOutputStream(DiskFileItem.java:557)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:362)
at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
at com.szk.system.service.file.FileUpload.getFileItems(FileUpload.java:211)
at com.szk.system.service.file.FileUpload.UploadFile(FileUpload.java:68)