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

Clover fails to instrument source code with TYPE_USE annotations in instanceof with array of primitives #186

Closed
satob opened this issue Sep 14, 2022 · 0 comments · Fixed by #187
Labels
bug Something isn't working resolved
Milestone

Comments

@satob
Copy link
Contributor

satob commented Sep 14, 2022

Clover fails to instrument source code with TYPE_USE annotations in instanceof with array of primitives

When you have the folowing code:

package typeannotation.instanceofoperator;

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

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

/* Testcase for typeSpec */
public class TypeAnnotationInstanceofOperator {
    public void typeAnnotation(Object obj) {
        if (obj instanceof @AnnotationForType1 String) {
            System.out.println(obj);
        }
        if (obj instanceof @AnnotationForType1 @AnnotationForType2 int[]) {
            System.out.println(obj);
        }
    }
}

@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\instanceofoperator\TypeAnnotationInstanceofOperator.java:15:13:unexpected token: obj
	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 jdk.internal.reflect.GeneratedMethodAccessor33.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.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.testTypeAnnotationInstanceofOperator(JavaSyntax18CompilationTest.groovy:484)
	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 15:13: unexpected token: obj
	at com.atlassian.clover.instr.java.JavaRecognizer.conditionalExpression(JavaRecognizer.java:5171)
	at com.atlassian.clover.instr.java.JavaRecognizer.assignmentExpression(JavaRecognizer.java:5038)
	at com.atlassian.clover.instr.java.JavaRecognizer.expression(JavaRecognizer.java:4081)
	at com.atlassian.clover.instr.java.JavaRecognizer.statement(JavaRecognizer.java:3623)
	at com.atlassian.clover.instr.java.JavaRecognizer.outerCompoundStmt(JavaRecognizer.java:3372)
	at com.atlassian.clover.instr.java.JavaRecognizer.field(JavaRecognizer.java:2950)
	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)
	... 49 more
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working resolved
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants