hosuaby / inject-resources

Simple and convenient way to read content of resource in Java.
http://inject-resources.hosuaby.io
Apache License 2.0
54 stars 5 forks source link

Getting Error java.lang.ExceptionInInitializerError #12

Closed bachhavdipak closed 3 years ago

bachhavdipak commented 3 years ago
import com.adelean.inject.resources.junit.jupiter.TestWithResources;
import com.adelean.inject.resources.junit.jupiter.WithGson;
import com.google.gson.Gson;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.Map;

@TestWithResources
@DisplayName("@GivenJsonResource")
public class BeanWithJsonResource {

    @WithGson
    Gson gson = new Gson();

    @GivenJsonResource("/Test/sponge-bob.json")
    Map<String, Object> jsonAsMap;

    @Test
    @DisplayName("injects JSON content into Map instance field")
    public void testInjectTextIntoStringInstanceField() {
        for (String keys : jsonAsMap.keySet())
        {
            System.out.println(keys + ":"+ jsonAsMap.get(keys));
        }
    }

}

Build.gradle

    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.1'
    testCompile group: 'com.adelean', name: 'inject-resources-core', version: '0.1.0'
    testCompile group: 'com.adelean', name: 'inject-resources-junit-jupiter', version: '0.1.0'
    implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.7'

Error:


   at com.adelean.inject.resources.junit.jupiter.TestWithResourcesExtension.provideParsers(TestWithResourcesExtension.java:145)
    at com.adelean.inject.resources.junit.jupiter.TestWithResourcesExtension.inject(TestWithResourcesExtension.java:140)
    at com.adelean.inject.resources.junit.jupiter.TestWithResourcesExtension.beforeAll(TestWithResourcesExtension.java:42)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeBeforeAllCallbacks$8(ClassBasedTestDescriptor.java:368)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeBeforeAllCallbacks(ClassBasedTestDescriptor.java:368)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:192)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:78)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:136)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
    at java.util.ArrayList.forEach(ArrayList.java:1259)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:108)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:96)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:75)
    at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99)
    at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
    at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
    at com.sun.proxy.$Proxy2.stop(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:133)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
    at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
    at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724)
    at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531)
    at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355)
    at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72)
    at java.lang.Class.createAnnotationData(Class.java:3521)
    at java.lang.Class.annotationData(Class.java:3510)
    at java.lang.Class.getDeclaredAnnotation(Class.java:3458)
    at com.adelean.inject.resources.commons.AnnotationUtils.findAnnotation(AnnotationUtils.java:35)
    at com.adelean.inject.resources.commons.AnnotationUtils.findAnnotation(AnnotationUtils.java:22)
    at com.adelean.inject.resources.commons.AnnotationSupport.lambda$allResourceAnnotations$5(AnnotationSupport.java:155)
    at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:174)
    at java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1556)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
    at com.adelean.inject.resources.commons.AnnotationSupport.allResourceAnnotations(AnnotationSupport.java:158)
    at com.adelean.inject.resources.junit.jupiter.core.Annotations.<clinit>(Annotations.java:11)

Disconnected from the target VM, address: 'localhost:58930', transport: 'socket'
BeanWithJsonResource > initializationError FAILED
    java.lang.ExceptionInInitializerError at TestWithResourcesExtension.java:145
        Caused by: java.lang.ArrayStoreException at AnnotationParser.java:724
hosuaby commented 3 years ago

Hello @bachhavdipak.

For JUnit 5.7.x please use the latest version 0.2.2.

hosuaby commented 3 years ago

@bachhavdipak since version 0.2.x project moved on maven central into another namespace io.hosuaby.

You just need to change your dependencies as following:

testCompile group: 'io.hosuaby', name: 'inject-resources-core', version: '0.2.2'
testCompile group: 'io.hosuaby', name: 'inject-resources-junit-jupiter', version: '0.2.2'

Do not forget to declare Maven central repo if it is not done yet:

repositories {
    mavenCentral()
}

You can find more info in the doc: https://hosuaby.github.io/inject-resources/0.2.2/asciidoc/#inject-resources-junit-jupiter

hosuaby commented 3 years ago

@bachhavdipak what is your JDK version ? Note: the minimal java version required is Java 8

bachhavdipak commented 3 years ago

@hosuaby

I am using below JDK version.

java version "1.8.0_281" Java(TM) SE Runtime Environment (build 1.8.0_281-b09)

hosuaby commented 3 years ago

@bachhavdipak Not sure it will help, but try add this to your grandle file:

java {
    disableAutoTargetJvm()
}
bachhavdipak commented 3 years ago

Thank you so much for your reply.

Yes finally it's working now. Thanks for your help.

On Sun, Jun 6, 2021, 9:26 AM Alexei KLENIN @.***> wrote:

@bachhavdipak https://github.com/bachhavdipak Not sure it will help, but try add this to your grandle file:

java { disableAutoTargetJvm() }

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/hosuaby/inject-resources/issues/12#issuecomment-855360441, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASMJ2WQLXAZBFFDWO4CYCTLTRMWL3ANCNFSM46EK2SQA .