英文:
Intellij Junit causes java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
问题
我正在尝试将 SendGrid 集成到我们处理电子邮件的一个仓库中。但是我的 JUnit 测试一直抛出上述异常。我已经大致浏览了这里大部分关于运行 JAR 文件以及与 cglib 存在问题的帖子,并且我确实下载了最新的 Mockito-all(1.10.19)。我能够构建 JAR 文件并在排除签名文件后使其运行起来,但我的问题是如何让 JUnit 正常工作呢?
基本上我所做的就是尝试模拟 SendGrid 类。
private SendGrid mockApiClient = Mockito.mock(SendGrid.class);
以下是我如何在项目中引入它的方式:(是的,那是 Ivy)
<dependency org="com.sendgrid" name="sendgrid-java" rev="4.6.5" conf="uber-jar->default"/>
抛出异常的堆栈跟踪如下:
java.lang.SecurityException: 无效的签名文件摘要(Invalid signature file digest for Manifest main attributes)
at sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:330)
at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:263)
at java.util.jar.JarVerifier.processEntry(JarVerifier.java:318)
at java.util.jar.JarVerifier.update(JarVerifier.java:230)
at java.util.jar.JarFile.initializeVerifier(JarFile.java:383)
at java.util.jar.JarFile.ensureInitialization(JarFile.java:617)
at java.util.jar.JavaUtilJarAccessImpl.ensureInitialization(JavaUtilJarAccessImpl.java:69)
at sun.misc.URLClassPath$JarLoader$2.getManifest(URLClassPath.java:991)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:451)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2611)
at java.lang.Class.getDeclaredFields(Class.java:1944)
at org.junit.runners.model.TestClass.<init>(TestClass.java:49)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:75)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:57)
at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:10)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
英文:
I am trying to integrate sendgrid into one of our repo's that handles emails. But my Junit tests keep throwing the mentioned Exception. I've skimmed through most of the posts on here talking about running the jar and issues around cglib and I do have the latest Mockito-all (1.10.19) pulled down. I'm able to build the jar and get it to run after excluding the signature files but my question is how do I get the Junit to work??
Basically all I'm doing is trying to mock the SendGrid class.
private SendGrid mockApiClient = Mockito.mock(SendGrid.class);
Here's how I've included it in the project: (yes thats ivy)
<dependency org="com.sendgrid" name="sendgrid-java" rev="4.6.5" conf="uber-jar->default"/>
The stacktrace of the exception thrown is as follows:
java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
at sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:330)
at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:263)
at java.util.jar.JarVerifier.processEntry(JarVerifier.java:318)
at java.util.jar.JarVerifier.update(JarVerifier.java:230)
at java.util.jar.JarFile.initializeVerifier(JarFile.java:383)
at java.util.jar.JarFile.ensureInitialization(JarFile.java:617)
at java.util.jar.JavaUtilJarAccessImpl.ensureInitialization(JavaUtilJarAccessImpl.java:69)
at sun.misc.URLClassPath$JarLoader$2.getManifest(URLClassPath.java:991)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:451)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2611)
at java.lang.Class.getDeclaredFields(Class.java:1944)
at org.junit.runners.model.TestClass.<init>(TestClass.java:49)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:75)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:57)
at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:10)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
答案1
得分: 0
因为我之前下载了一个较早版本的fat jar,所以出现了这个问题。当我移除了那个jar文件,清除了缓存,并重新拉取了所有内容后,我得到了一个没有那些签名文件的jar文件。
现在一切都正常工作。
英文:
This was occurring because I had a fat jar downloaded from a while back. When I removed that, cleared my cache and re-pulled everything I was able to get a jar which did not have those signature files.
Everything now works
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论