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

Comments

Projects
None yet
4 participants
@stevenschlansker

stevenschlansker commented Mar 25, 2014

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 marchof added core labels Mar 25, 2014

@marchof

This comment has been minimized.

Show comment
Hide comment
@marchof

marchof Mar 25, 2014

Member

@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.

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

This comment has been minimized.

Show comment
Hide comment
@stevenschlansker

stevenschlansker Mar 25, 2014

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);
}

stevenschlansker commented Mar 25, 2014

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

This comment has been minimized.

Show comment
Hide comment
@Godin

Godin Mar 26, 2014

Member

@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

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

This comment has been minimized.

Show comment
Hide comment
@marchof

marchof Mar 26, 2014

Member

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

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 from Jacoco reporter does not work with Java 8 to Java 8: Failure with default methods in interfaces Apr 22, 2014

@saden1

This comment has been minimized.

Show comment
Hide comment
@saden1

saden1 Apr 30, 2014

When should we expect a release with a fix?

saden1 commented Apr 30, 2014

When should we expect a release with a fix?

@marchof

This comment has been minimized.

Show comment
Hide comment
@marchof

marchof Apr 30, 2014

Member

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.

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.