验证注释参数(Groovy)

时间:2017-10-16 16:26:20

标签: java groovy annotations

我正在尝试实现注释参数的验证,但是“出了问题”。有关于此的任何观点吗?

@Retention(RetentionPolicy.RUNTIME)
@Target([ElementType.METHOD])
@Constraint(validatedBy = SomeValidator.class)
@ExtensionAnnotation(*****.class)
@interface SomeAnnotation {
   int someProperty() default 2
}

class SomeValidator implements ConstraintValidator<SomeAnnotation, Integer> {
    @Override
        void initialize(SomeAnnotation constraintAnnotation) {
    }
    @Override
    boolean isValid(Integer value, ConstraintValidatorContext context) {
        value > 1
    }
}

我有以下错误

Error:Groovyc: While compiling systest_main: BUG! exception in phase 'semantic analysis' in source unit '******SomeValidator.groovy' sun.reflect.annotation.TypeNotPresentExceptionProxy
    at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:927)
    at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:585)
    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:534)
    at org.jetbrains.groovy.compiler.rt.GroovyCompilerWrapper.compile(GroovyCompilerWrapper.java:62)
    at org.jetbrains.groovy.compiler.rt.DependentGroovycRunner.runGroovyc(DependentGroovycRunner.java:115)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.jetbrains.groovy.compiler.rt.GroovycRunner.intMain2(GroovycRunner.java:136)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.jetbrains.jps.incremental.groovy.InProcessGroovyc.runGroovycInThisProcess(InProcessGroovyc.java:158)
    at org.jetbrains.jps.incremental.groovy.InProcessGroovyc.lambda$runGroovyc$0(InProcessGroovyc.java:88)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
    at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724)
    at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531)
    at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355)
    at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72)
    at java.lang.Class.createAnnotationData(Class.java:3521)
    at java.lang.Class.annotationData(Class.java:3510)
    at java.lang.Class.getAnnotations(Class.java:3446)
    at org.jetbrains.groovy.compiler.rt.ClassDependencyLoader.loadClassDependencies(ClassDependencyLoader.java:96)
    at org.jetbrains.groovy.compiler.rt.DependentGroovycRunner$6.loadClassDependencies(DependentGroovycRunner.java:474)
    at org.jetbrains.groovy.compiler.rt.ClassDependencyLoader.loadDependencies(ClassDependencyLoader.java:34)
    at org.jetbrains.groovy.compiler.rt.DependentGroovycRunner$7$1.loadClass(DependentGroovycRunner.java:493)
    at org.codehaus.groovy.control.ClassNodeResolver.tryAsLoaderClassOrScript(ClassNodeResolver.java:183)

0 个答案:

没有答案