Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 8: Failure with default methods in interfaces #201

Closed
stevenschlansker opened this issue Mar 25, 2014 · 6 comments
Closed

Java 8: Failure with default methods in interfaces #201

stevenschlansker opened this issue Mar 25, 2014 · 6 comments
Assignees
Labels
component: core type: bug 🐛 Something isn't working
Milestone

Comments

@stevenschlansker
Copy link

Jacoco can fail on Java 8 classes, in this particular case one with a default method implementation on an interface:

Caused by: java.io.IOException: Error while analyzing class /Users/steven/.../DiscoveryClient.class.
    at org.jacoco.core.analysis.Analyzer.analyzerError(Analyzer.java:150)
    at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:144)
    at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:175)
    at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:208)
    at org.jacoco.maven.BundleCreator.createBundle(BundleCreator.java:78)
    at org.jacoco.maven.AbstractReportMojo.createReport(AbstractReportMojo.java:219)
    at org.jacoco.maven.AbstractReportMojo.executeReport(AbstractReportMojo.java:193)
    ... 22 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 3
    at org.jacoco.core.internal.analysis.MethodAnalyzer.addProbe(MethodAnalyzer.java:288)
    at org.jacoco.core.internal.analysis.MethodAnalyzer.visitInsnWithProbe(MethodAnalyzer.java:224)
    at org.jacoco.core.internal.flow.MethodProbesAdapter.visitInsn(MethodProbesAdapter.java:76)
    at org.objectweb.asm.tree.InsnNode.accept(InsnNode.java:80)
    at org.objectweb.asm.tree.InsnList.accept(InsnList.java:162)
    at org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:815)
    at org.jacoco.core.internal.flow.ClassProbesAdapter$1.visitEnd(ClassProbesAdapter.java:145)
    at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1021)
    at org.objectweb.asm.ClassReader.accept(ClassReader.java:693)
    at org.objectweb.asm.ClassReader.accept(ClassReader.java:506)
    at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:107)
    at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:142)
    ... 27 more

asm does not support Java 8 until 5.0.1, additionally maybe Jacoco itself needs some fixups for Java 8.

@marchof
Copy link
Member

marchof commented Mar 25, 2014

@stevenschlansker Thanks for reporting this! JaCoCo 0.7.0 is based on ASM5 and is supposed to support Java 8.

However, the instrumenter assumes that a interface does contain at most one method () which does not hold true for Java 8 interfaces with default methods. Therefore a wrong probe array length is calculated which results in the ArrayIndexOutOfBoundsException you encountered. I will see how we can fix this for Java 8.

@marchof marchof added this to the 0.7.1 milestone Mar 25, 2014
@marchof marchof self-assigned this Mar 25, 2014
@stevenschlansker
Copy link
Author

Awesome. In case it is helpful, here is the interface I am having trouble with:

public interface DiscoveryClient extends AnnouncementPublisher
{
    default Announcement findAnnouncement(ServiceLookup lookup, LookupHint... hints)
    {
        final List<Announcement> announcements = findAnnouncements(lookup, hints);
        return announcements.isEmpty() ? null : announcements.get(ThreadLocalRandom.current().nextInt(announcements.size()));
    }

    default List<Announcement> findAllAnnouncements()
    {
        return findAnnouncements(ServiceLookup.with());
    }

    List<Announcement> findAnnouncements(ServiceLookup lookup, LookupHint... hints);
}

@Godin
Copy link
Member

Godin commented Mar 26, 2014

@marchof in any case seems that we must upgrade to ASM 5.0.1 - see http://mail.ow2.org/wws/arc/asm/2014-03/msg00034.html

marchof added a commit that referenced this issue Mar 26, 2014
@marchof
Copy link
Member

marchof commented Mar 26, 2014

@Godin Fortunately only issue 317127 seems to affect us. Anyways, I upgraded to 5.0.1.

@marchof marchof changed the title Jacoco reporter does not work with Java 8 Java 8: Failure with default methods in interfaces Apr 22, 2014
@saden1
Copy link

saden1 commented Apr 30, 2014

When should we expect a release with a fix?

@marchof
Copy link
Member

marchof commented Apr 30, 2014

I found a solution for the problem. Need to cleanup the code and add more tests. The release should be available within 1-2 weeks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
component: core type: bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants