0

When the member object passed on to the getGenericType() method in AttributeSourceGenerator.java corresponds to 'public org.json.JSONArray', then the following exception is thrown :-

java.lang.IllegalStateException: Failed to create attribute for member: public org.json.JSONArray com.Mypackage.Myclass.jsonArrayfieldName
    at com.googlecode.cqengine.codegen.AttributeBytecodeGenerator.createAttributes(AttributeBytecodeGenerator.java:141)
    at com.googlecode.cqengine.codegen.AttributeBytecodeGenerator.createAttributes(AttributeBytecodeGenerator.java:54)
    at myAppMethod(MyCustomClass.java:102)
    at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:52)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:124)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:167)
    at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:219)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:79)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:475)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:397)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:81)
    at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:255)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:244)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265)
    at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:234)
    at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:680)
    at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:394)
    at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:346)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:366)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:319)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.ClassCastException: class java.lang.Class cannot be cast to class java.lang.reflect.ParameterizedType (java.lang.Class and java.lang.reflect.ParameterizedType are in module java.base of loader 'bootstrap')
    at com.googlecode.cqengine.codegen.AttributeSourceGenerator.getGenericType(AttributeSourceGenerator.java:379)
    at com.googlecode.cqengine.codegen.AttributeBytecodeGenerator.createAttributes(AttributeBytecodeGenerator.java:109)
    ... 54 more

In the workflow, the getGenericType() on the JSONArray member (type casted to 'Field') is called, which returns an instance of java.lang.Class. When an attempt to type cast this instance to ParameterizedType is made, the ClassCastException is thrown :-

static ParameterizedType getGenericType(Member member) {
    if (member instanceof Field) {
        return (ParameterizedType)((Field) member).getGenericType();
    }
    else if (member instanceof Method) {
        return (ParameterizedType)((Method) member).getGenericReturnType();
    }
    else throw new IllegalStateException("Unsupported member type: " + member);
}

This error/exception is breaking an important functionality in our application. I would like to understand more about the above code. In my opinion, the above code would throw an error everytime a JSONArray member is used. Is it a known incompatibility between cqengine and JSONArray, and is there a workaround for it? Please let me know if I'm missing something.

0 Answers0