question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Meta-annotations written at use-site are ignored

See original GitHub issue

Compiler version

3.0.0

Minimized code

This is an issue I’ve encountered while trying to port squeryl to scala 3.

In a MyColumnBase.java file:

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface MyColumnBase {

    String value() default "";
    
    String name() default "";

}

and in a scala file:

import annotation.meta.field

type MyColumn = MyColumnBase @field

class MyTable(
  @MyColumn(name="BRAND_NAME")
  val brandName: String
) {
    @MyColumn(name="WEIGHT")
    val weightInGrams: Option[String] = None
}

val clasz = classOf[MyTable]

for(m <- clasz.getDeclaredFields) {
  m.setAccessible(true)
  if(m.getName == "weightInGrams" || m.getName == "brandName"){
    println(s"inspecting field ${m.getName}")
    assert(m.getAnnotations().size == 1, s"no annotation found for ${m.getName}")
  }
}

Output

Array() had size 0 instead of expected size 1 no annotation found for brandName

Expectation

I would expect to see the annotation on the field brandName. In scala 2.13, I can at least.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
smartercommented, Dec 5, 2021

Same thing yes.

1reaction
smartercommented, May 21, 2021

In that case the meta-annotation isn’t needed since we’re directly annotating a field (from https://www.scala-lang.org/api/current/scala/annotation/meta/index.html):

By default, annotations on (val-, var- or plain) constructor parameters end up on the parameter, not on any other entity. Annotations on fields by default only end up on the field.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does Hibernate Validator ignore my custom annotations ...
I was debugging into Hibernate Validator and when it lists found annotations, the custom ones are not added in the bean meta data...
Read more >
Nullable meta annotations are ignored · Issue #973 - GitHub
A schema that contains @NotBlank inside a meta-annotation is not marked as required but should be. Provide with a sample code (HelloController) ...
Read more >
Annotations | Kotlin
Annotations are means of attaching metadata to code. To declare an annotation, put the annotation modifier in front of a class:.
Read more >
Support Java custom meta-annotations to selectively ignore ...
In our code base, the objects exchanged via our REST API are defined as classes (views) with all fields public, no constructor (i.e....
Read more >
Wikipedia:Ignored feature requests
The village pump is crowded, and is explicitly not for the requesting of new features. Use MediaZilla or the correct meta page instead....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found