Skip to content

Clover fails to instrument source code with TYPE_USE annotations in super/extends clause in generics #184

@satob

Description

@satob

When you have the folowing code:

package typeannotation.fielddeclarationgenerics;

import static java.lang.annotation.RetentionPolicy.*;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.util.HashMap;

/* Testcase for singleTypeArgument */
public class TypeAnnotationInFieldDeclarationGenerics<T> {
    private final HashMap<@AnnotationForType1 String, String> map1 = new HashMap<>();
    private final HashMap<@AnnotationForType1 @AnnotationForType2 String, String> map2 = new HashMap<>();
    private final HashMap<String, @AnnotationForType1 int[]> map3 = new HashMap<>();
    private final HashMap<String, @AnnotationForType1 @AnnotationForType2 T> map4 = new HashMap<>();
    private final HashMap<String, @AnnotationForType1 ?> map5 = new HashMap<>();
    private final HashMap<String, @AnnotationForType1 @AnnotationForType2 ?> map6 = new HashMap<>();
    private final HashMap<String, @AnnotationForType1 ? extends @AnnotationForType1 int[]> map7 = new HashMap<>();
    private final HashMap<String, @AnnotationForType1 @AnnotationForType2 ? super @AnnotationForType1 @AnnotationForType2 T> map8 = new HashMap<>();

    public static void main(String args[]) {
        TypeAnnotationInFieldDeclarationGenerics<?> j = new TypeAnnotationInFieldDeclarationGenerics<Object>();
        j.getSize();
    }
    public void getSize() {
        System.out.println(map1.size());
        System.out.println(map2.size());
        System.out.println(map3.size());
        System.out.println(map4.size());
        System.out.println(map5.size());
        System.out.println(map6.size());
        System.out.println(map7.size());
        System.out.println(map8.size());
    }
}

@Retention(RUNTIME) @Target({ElementType.TYPE_USE})
@interface AnnotationForType1 {
}

@Retention(RUNTIME) @Target({ElementType.TYPE_USE})
@interface AnnotationForType2 {
}

This code causes Clover instrumentation to throw the exception below. Removing the type annotation immediately fixes the problem.

com.atlassian.clover.api.CloverException: C:\home\satob\git\clover\clover-core\src\test\resources\javasyntax1.8\typeannotation\fielddeclarationgenerics\TypeAnnotationInFieldDeclarationGenerics.java:18:5:unexpected token: private
	at com.atlassian.clover.instr.java.Instrumenter.instrument(Instrumenter.java:159)
	at com.atlassian.clover.CloverInstr.execute(CloverInstr.java:110)
	at com.atlassian.clover.CloverInstr.mainImpl(CloverInstr.java:86)
	at jdk.internal.reflect.GeneratedMethodAccessor22.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
	at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.invoke(StaticMetaMethodSite.java:46)
	at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.call(StaticMetaMethodSite.java:91)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
	at com.atlassian.clover.JavaSyntaxCompilationTestBase.instrumentSourceFile(JavaSyntaxCompilationTestBase.groovy:157)
	at jdk.internal.reflect.GeneratedMethodAccessor20.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
	at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:185)
	at com.atlassian.clover.JavaSyntaxCompilationTestBase.instrumentSourceFile(JavaSyntaxCompilationTestBase.groovy:138)
	at jdk.internal.reflect.GeneratedMethodAccessor19.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
	at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:177)
	at com.atlassian.clover.JavaSyntaxCompilationTestBase.instrumentAndCompileSourceFile(JavaSyntaxCompilationTestBase.groovy:118)
	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.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
	at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:157)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:193)
	at com.atlassian.clover.JavaSyntax18CompilationTest.testTypeAnnotationInFieldDeclarationGeneric(JavaSyntax18CompilationTest.groovy:547)
	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 junit.framework.TestCase.runTest(TestCase.java:176)
	at junit.framework.TestCase.runBare(TestCase.java:141)
	at junit.framework.TestResult$1.protect(TestResult.java:122)
	at junit.framework.TestResult.runProtected(TestResult.java:142)
	at junit.framework.TestResult.run(TestResult.java:125)
	at junit.framework.TestCase.run(TestCase.java:129)
	at junit.framework.TestSuite.runTest(TestSuite.java:252)
	at junit.framework.TestSuite.run(TestSuite.java:247)
	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:536)
	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1178)
	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:1005)
Caused by: line 18:5: unexpected token: private
	at com.atlassian.clover.instr.java.JavaRecognizer.field(JavaRecognizer.java:2996)
	at com.atlassian.clover.instr.java.JavaRecognizer.classBlock(JavaRecognizer.java:2344)
	at com.atlassian.clover.instr.java.JavaRecognizer.classDefinition(JavaRecognizer.java:1240)
	at com.atlassian.clover.instr.java.JavaRecognizer.typeDefinition2(JavaRecognizer.java:1167)
	at com.atlassian.clover.instr.java.JavaRecognizer.typeDefinition(JavaRecognizer.java:1071)
	at com.atlassian.clover.instr.java.JavaRecognizer.compilationUnit(JavaRecognizer.java:983)
	at com.atlassian.clover.instr.java.Instrumenter.instrument(Instrumenter.java:211)
	at com.atlassian.clover.instr.java.Instrumenter.instrument(Instrumenter.java:124)
	... 50 more

Metadata

Metadata

Labels

bugSomething isn't workingresolved

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions