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 annotations are not applied correctly classes defined within traits #11790

stringbean opened this issue Nov 1, 2019 · 0 comments


Copy link

@stringbean stringbean commented Nov 1, 2019

There are some edge cases for the targeting of annotations using the meta-annotations where they are not getting applied correctly for classes defined within traits.

According to the scaladocs for scala.annotation.meta:

The target meta-annotations can be put on the annotation type when instantiating the annotation. In the following example, the annotation @id will be added only to the bean getter getX.

import javax.persistence.Id
class A {
  @(Id @beanGetter) @BeanProperty val x = 0

When the meta-annotations are used on classes defined in standalone compilation units or within objects everything behaves correctly. If the annotations are applied to classes defined within traits they get applied to extra methods that shouldn't be. In Scala 2.11.12 and below this only affected a couple of scenarios but in 2.12.0 and newer the behaviour has regressed significantly.

I've created a test harness that applies the different meta-annotations and outputs where the annotations were actually applied. The harness can be found in this gist.

A summary of the results can be seen below:

Test Case Expected 2.11 2.12 2.13
TestBean.defaultTarget C C C C
TestBean.fieldTarget F F F F
TestBean.getterTarget M M M M
TestBean.beanPropertyDefault C C C C
TestBean.beanPropertyField F F F F
TestBean.beanPropertyGetter M M M M
TestBean.beanPropertyBeanGetter B B B B
WrappedBean.defaultTarget C - M M
WrappedBean.fieldTarget F F FMC FMC
WrappedBean.getterTarget M M M M
WrappedBean.beanPropertyDefault C - MB MB
WrappedBean.beanPropertyField F FC FMCB FMCB
WrappedBean.beanPropertyGetter M MC MC MC
WrappedBean.beanPropertyBeanGetter B B B B


  • C: constructor
  • F: field
  • M: getter method
  • B: bean getter method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
1 participant
You can’t perform that action at this time.