Understanding how to resolve "Inconsistent stackmap frames" exception - maven

I get an exception on startup of the web application as guice is trying to construct the class mentioned.
java.lang.VerifyError: Inconsistent stackmap frames at branch target 2770 in method com.aptusi.apps.magazine.api.servlet.internal.EditorServlet.service(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;Ljava/lang/String;Lcom/aptusi/persistence/runtime/framework/DboSession;)V at offset 200
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2483)
at java.lang.Class.getDeclaredConstructors(Class.java:1891)
at com.google.inject.spi.InjectionPoint.forConstructorOf(InjectionPoint.java:243)
at com.google.inject.internal.ConstructorBindingImpl.create(ConstructorBindingImpl.java:96)
at com.google.inject.internal.InjectorImpl.createUninitializedBinding(InjectorImpl.java:629)
at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:845)
at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:772)
at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:256)
at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:205)
at com.google.inject.internal.InjectorImpl.getBinding(InjectorImpl.java:146)
at com.google.inject.internal.InjectorImpl.getBinding(InjectorImpl.java:66)
at com.google.inject.servlet.ServletDefinition.init(ServletDefinition.java:103)
at com.google.inject.servlet.ManagedServletPipeline.init(ManagedServletPipeline.java:82)
at com.google.inject.servlet.ManagedFilterPipeline.initPipeline(ManagedFilterPipeline.java:102)
at com.google.inject.servlet.GuiceFilter.init(GuiceFilter.java:172)`
I know about the -XX:-UseSplitVerifier and -noverify jvm options but I don't want to use as I want to ensure that all the code in this project is at least java version 7.
In order to do this It would be useful to understand where exactly this is occurring in my code, its not clear to me what the offset of 200 mentioned is but can it be related to a line number?
Also does anyone know of a way that I can find out the java versions of all classes on my classpath, I am using maven so there are a lot of dependencies, so I'm looking for an automated way of finding any classes on the classpath that may have been compiled to a lower java version than 1.7?

To find the version of a classfile, just look at the 8th byte of the classfile. It will be 51 for Java 7 classes. A framework like ASM will do this for you.
As far as the error goes, it means your classfile is malformed. How did you create these classes? Did you do any bytecode manipulation? If so, you probably have a bug in your code.

Related

OptaPlanner got java reflection error in Spring boot

I just tried to run an OptaPlanner project in Spring Boot, but there's only very simple text in OptaPlanner User Guide for Spring.
Actually, I think it is very easy to copy all domain objects, configuration files and drools files from an OptaPlanner project to Spring Boot project without any changes, but the only question is how to call Solver's solve method.
I made it run after Spring Boot startup with a class (named CommandLineAppStartupRunner) which implements CommandLineRunner interface, and I called solve method in its run method. Finally, I got an exception like follows:
Caused by: java.lang.IllegalArgumentException: Can not set org.optaplanner.core.api.score.buildin.hardmediumsoft.HardMediumSoftScore field springbootcloudbalance.domain.CloudBalance.score to springbootcloudbalance.domain.CloudBalance
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58)
at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:36)
at java.lang.reflect.Field.get(Field.java:393)
at org.optaplanner.core.impl.domain.common.accessor.ReflectionFieldMemberAccessor.executeGetter(ReflectionFieldMemberAccessor.java:54)
at org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor.getScore(SolutionDescriptor.java:1071)
at org.optaplanner.core.impl.score.director.AbstractScoreDirector.cloneSolution(AbstractScoreDirector.java:212)
at org.optaplanner.core.impl.solver.scope.DefaultSolverScope.setWorkingSolutionFromBestSolution(DefaultSolverScope.java:230)
at org.optaplanner.core.impl.solver.AbstractSolver.solvingStarted(AbstractSolver.java:75)
at org.optaplanner.core.impl.solver.DefaultSolver.solvingStarted(DefaultSolver.java:210)
at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:190)
at springbootcloudbalance.CommandLineAppStartupRunner.run(CommandLineAppStartupRunner.java:55)
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:818)
... 10 common frames omitted
I checked the code, and found the exception throws because the object from field.getDeclaringClass() is a different instance from the one from var1.getClass(). I'm afraid it due to the implementation of java reflection conflicts between OptaPlanner and Spring Boot.
The version I used is as follows:
OptaPlanner 7.11.0.Final
Spring Boot 2.0.5.RELEASE
JVM 1.8.0_181
Removing the spring-boot-devtools dependency fixes this error. Another SO question similar to this one explains it has something to do with different classloaders: Optaplanner's Drools working memory is empty. The accepted answer also mentions a possible fix:
To fix it, configure spring dev tools to load Drools libraries in the RestartClassLoader, together with the project's classes: using-boot-devtools-customizing-classload
Nick's answer is correct. This is just to figure out what's going on.
This line means that optaplanner is extracting CloudBalance.getScore():
at org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor.getScore(SolutionDescriptor.java:1071)
This line means that it's using a ReflectionFieldMemberAccessor for that, which is just way to read a field through reflection (including private fields):
at org.optaplanner.core.impl.domain.common.accessor.ReflectionFieldMemberAccessor.executeGetter(ReflectionFieldMemberAccessor.java:54)
Now the error message is where it gets interesting:
Can not set ...HardMediumSoftScore field ...CloudBalance.score to ...CloudBalance
It looks like basically doing:
CloudBalance cloudBalance2 = cloudBalance.getScore();
Huh?
Musa provided this answer, but someone deleted it, despite that the JIRA link is extremely relevant, as it points out which version of OptaPlanner will deal better with this problem:
"An issue was submitted to OptaPlanner to provide better error messages for such cases: https://issues.jboss.org/browse/PLANNER-1586. Feel free to add any comments or suggestions."

Tomcat 7 to Tomcat 8 migration: IncompatibleClassChangeError: Found class org.objectweb.asm.AnnotationVisitor

I am facing the following problem. Using a compiled software I am trying to launch it on Tomcat 8 instead of Tomcat 7. After resolving some minor problems I get stuck at this one:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ... Invocation of init method failed; nested exception is java.lang.IncompatibleClassChangeError: Found class org.objectweb.asm.AnnotationVisitor, but interface was expected
Reading around, it seems like it comes from Spring version difference. Trouble is I'm not touching the application here at all. Tomcat 7 and Tomcat 8 get exactly same program to launch.
Could I ask you for your suggestions on solving it?
On the way of investigating the problem I've learned about this ticket: https://bz.apache.org/bugzilla/show_bug.cgi?id=57129
It looks like Tomcat 8, as opposed to earlier Tomcat version does not load classes alphabetically. In my project it caused a problem as libraries holding different versions of asm where used.
Note: In the ticket from above - raised to apache, someone links the workaround at https://github.com/openwide-java/tomcat-classloader-ordered. For me it did not work, though.
In the end we had to go through a complex work of removing dependencies and fixing the project up so that it relies on one lib version only.
Good luck for everyone struggling with similar stuff!

Spring SAML + Wildfly 8 + IBM Jdk (1.7) - java.lang.RuntimeException: org.w3c.dom.ls.LSException: [ERR 0462] An unsupported encoding is encountered

I am getting a error when deploying spring-saml application in Wildfly 8 with IBM JDK 1.7. Interestingly Googling got me no answers.
The error stacktrace is
Caused by: org.w3c.dom.ls.LSException: [ERR 0462] An unsupported encoding is encountered.
at org.apache.xml.serializer.dom3.LSSerializerImpl.write(Unknown Source) [xml.jar:]
at org.opensaml.xml.util.XMLHelper.writeNode(XMLHelper.java:892)
at org.opensaml.xml.util.XMLHelper.writeNode(XMLHelper.java:872)
at org.opensaml.xml.util.XMLHelper.nodeToString(XMLHelper.java:834)
at org.opensaml.xml.XMLConfigurator.load(XMLConfigurator.java:159)
at org.opensaml.xml.XMLConfigurator.load(XMLConfigurator.java:143)
at org.opensaml.DefaultBootstrap.initializeXMLTooling(DefaultBootstrap.java:203)
at org.opensaml.DefaultBootstrap.initializeXMLTooling(DefaultBootstrap.java:186)
at org.opensaml.DefaultBootstrap.bootstrap(DefaultBootstrap.java:92)
at org.opensaml.PaosBootstrap.bootstrap(PaosBootstrap.java:27)
at org.springframework.security.saml.SAMLBootstrap.postProcessBeanFactory(SAMLBootstrap.java:42)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:696)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:686)
at org.springframework.context.support.AbstractApplicationContext.__refresh(AbstractApplicationContext.java:461)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:173)
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:194)
Any ideas?
I think the problem is the dependency between opensaml.jar and serializer.jar.
As you used Spring Security SAML plugin, you may be using the following libraries (as they are in the demo application):
opensaml-2.6.1.jar
spring-security-config-3.1.2.jar
spring-security-core-3.2.1.jar
spring-security-web-3.2.1.jar
spring-security-saml2-core-1.0.2.jar
Wildfly 8 (and 9 too) both are packed with serializer-2.7.1.jbossorg-1.jar (/modules/system/layers/base/org/apache/xalan/main) which seems to have some differences with the "standard" serializer-2.7.1.jar (https://mvnrepository.com/artifact/xalan/serializer/2.7.1).
I compared both jars and they contain the same classes and resources, however their sizes differ. The "standard" one was compiled with IBM JDK 1.3.1, JBoss version with Oracle JDK 1.6_20 - This is based on both MANIFEST.MF files.
Note opensaml.jar was compiled with the "standard" serializer library based on the Maven repository information.
I was searching for the source code of the "standard" serializer-2.7.1.jar but I could not find it. However, I found another 2.7.1 build, this time from Spring and compared with the one JBoss source, and they have some differences. I assume that if I compare the "standard" source code I will find the same. It is not a simple file renaming as I have seen before.
The next thing I did was a little bit of experimentation.
Firstly just dropped serializer-2.7.1.jar into my application.war/WEB-INF/lib, started Wildfly (v 8.2.1) and the application started without any issues. Removed the JAR and back to the exception.
Next, I changed WF’s xalan module to use serializer-2.7.1.jar instead serializer-2.7.1.jbossorg-1.jar (removed the jar file and edited module.xml). Started WF, and surprise, I got the same exception. I even tried changing to serializer-2.7.1.jbossorg-2.jar (packed with Wildfly 10) and serializer-2.7.2.jar (https://mvnrepository.com/artifact/xalan/serializer/2.7.2) and the exception still occurred.
Finally, I rolled back the module changes to the original state and created a custom WF module including serializer-2.7.1.jar and added the module dependency in the application “jboss-deployment-structure.xml”.
It is important to highlight the application starts without any issue (or additional serializer.jar) under WAS 8.5.5 and WAS Liberty Profile 8.5.5. (target production AS and another development AS respectively). Custom modules in Wildfly are handy to avoid modifying the application WAR on this kind of scenarios.
As an additional note, as part of my test to solve this issue I upgraded to the latest Spring-Security (3.2.9) and Open-SAML (2.6.4) and I needed to upgrade to serialize.jar to 2.7.2.
P.S. I worked with Mahe in the same project, but he left few months ago and I got the task to work out this issue.

Map Reduce Job: Protobuf related error

I am getting an error while running a Map Reduce job:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.hadoop.yarn.proto.YarnProtos$LocalResourceProto.hashLong(J)I
at org.apache.hadoop.yarn.proto.YarnProtos$LocalResourceProto.hashCode(YarnProtos.java:11655)
at org.apache.hadoop.yarn.api.records.impl.pb.LocalResourcePBImpl.hashCode(LocalResourcePBImpl.java:62)
at java.util.HashMap.hash(HashMap.java:362)
at java.util.HashMap.put(HashMap.java:492)
Doing a little google search, I bumped into a thread, which suggested this as proto version related error. It says that my application is having a dependency on proto3 with yarn using proto2.
According to my pom.xml, protobuf-java-2.6.1.jar is being used.
Can anyone please help me understand the issue and how to fix it?
This error indicates that the jar file used when the code was compiled is different from the jar file used when it was run. You need to make sure that you're using exactly the same version of the protobuf jar as the code was compiled against. If you didn't compile the code yourself, you'll need to figure out what version the provider used.

Deploying ojdbc14.jar in a code module for a FileNet code module

I'm trying to deploy a couple of jar files in a code module for an event action in FileNet P8 4.0 (the FileNet server runs on WebSphere 6.1). One of these jars is my custom code, and the other jar is the thin driver for Oracle called ojdbc14.jar (I also tried with ojdbc15.jar), the custom code uses the oracle jar in order to connect to a data source and get a connection using the JNDI name.
When the event action is executed (after a subscription is invoked) the code in my custom module is called OK, the problem occurs when my code needs to load classes from the Oracle jar, I get this cause:
ERROR - Mon Sep 21 16:42:17 UTC 2009 - com.ibm.websphere.naming.CannotInstantiateObjectException: Exception occurred while the JNDI NamingManager was processing a javax.naming.Reference object. [Root exception is java.lang.reflect.InvocationTargetException]
at com.ibm.ws.naming.util.Helpers.processSerializedObjectForLookupExt(Helpers.java:1000)
at com.ibm.ws.naming.util.Helpers.processSerializedObjectForLookup(Helpers.java:705)
at com.ibm.ws.naming.jndicos.CNContextImpl.processResolveResults(CNContextImpl.java:2093)
...
Caused by: java.lang.NoClassDefFoundError: oracle.jdbc.driver.OracleLog
at com.ibm.ws.rsadapter.dbutils.impl.OracleUtilityImpl.setLogVolume(OracleUtilityImpl.java:85)
at com.ibm.ws.rsadapter.spi.InternalOracleDataStoreHelper.setProperties(InternalOracleDataStoreHelper.java:142)
at com.ibm.ws.rsadapter.spi.WSRdbDataSource.(WSRdbDataSource.java:846)
at com.ibm.ws.rsadapter.spi.WSManagedConnectionFactoryImpl.setDataSourceProperties(WSManagedConnectionFactoryImpl.java:1947)
... 43 more
...
Caused by: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleLog
at java.net.URLClassLoader.findClass(URLClassLoader.java:496)
at com.ibm.ws.bootstrap.ExtClassLoader.findClass(ExtClassLoader.java:132)
at java.lang.ClassLoader.loadClass(ClassLoader.java:631)
at com.ibm.ws.bootstrap.ExtClassLoader.loadClass(ExtClassLoader.java:87)
at java.lang.ClassLoader.loadClass(ClassLoader.java:597)
... 48 more
Since I'm deploying the oracle jar with the code module, shouldn't FileNet should be able to find the class? Do you think I need to configure something else?
Thanks in advance.
Is it possible for your application to use WebSphere's own JDBC connection pools? When you set up a pool for a particulr database you get all the vendor-specific drivers installed there.
Generally, all manner of classpath and classloader confisions ensue when you try to place infrastructure code in your own applications. I don't know for certain that this is the case for your situation, but I do find taht staying on the known path in WebSphere tends to give the smoothest results.
I found the problem... somehow the ojdbc14.jar file got corrupted, so even when the classpath was correct and no matter what I tried to fix the problem, the problem was always there.
Thanks for the comments!

Resources