Monday, April 22, 2013

java.lang.VerifyError with Java 7 and Cobertura

I just added Cobertura to a Java 7 project and was disappointed that my unit tests started failing with:
 java.lang.VerifyError: Expecting a stackmap frame at branch target blah...  
Looks like cobertura's byte code instrumentation is not compatible with Java 7.  Java 7 changed the class format with the addition of a stack map used for verification and cobertura hasn't caught up yet - if ever.

Oracle does provide a way around the problem by using the -XX:UseSplitVerifier VM option.  I added it as an argument to the surefire-plugin configuration in my maven pom file.
 <plugin>  
    <groupId>org.apache.maven.plugins</groupId>  
    <artifactId>maven-surefire-plugin</artifactId>  
    <version>${surefire.plugin.version}</version>  
    <configuration>  
      <argLine>-XX:-UseSplitVerifier</argLine>  
    </configuration>    
 </plugin>  

Wednesday, April 10, 2013

Simple fix to missing tools.jar in JDK on Mac OS X

Today I ran into a situation where a 3rd-party pom.xml had a dependency on tools.jar.  I'm stuck using Java 6, due to project requirements, which means I have to use the Apple supplied JDK.  The problem is Apple bundled all the classes normally found in tools.tar into classes.jar.  Since I couldn't modify the pom file, I simply creating a symbolic link to classes.jar.
 $> sudo ln -s /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/tools.jar  
 $> sudo ln -s /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/lib  
Problem solved!