Skip to content

Scalac does not seem to support JSR 308 #9883

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

Open
scabug opened this issue Aug 9, 2016 · 2 comments
Open

Scalac does not seem to support JSR 308 #9883

scabug opened this issue Aug 9, 2016 · 2 comments

Comments

@scabug
Copy link

scabug commented Aug 9, 2016

JSR 308 brought annotations on type parameters such as

class SomeBean {
     Optional<@Base64 String> bs;
}

After a quick byte-code analysis (javap -v ... | grep Base64) the following scala code does not seem to compile properly:

case class SomeScalaBean(bs: Optional[String @Base64]) 

This was asked on SO: http://stackoverflow.com/questions/38833827/how-to-annotate-a-type-parameter-in-scala

@scabug
Copy link
Author

scabug commented Aug 9, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9883?orig=1
Reporter: Bruno Bieth (mustaghattack)
Affected Versions: 2.11.8
See #9853

@scabug scabug added this to the Backlog milestone Apr 7, 2017
@tmoschou
Copy link

tmoschou commented Sep 18, 2019

This is still an issue with annotation on type parameters being ignored by scalac. An example use case is implementing a custom Hibernate Validator ValueExtractor, which requires it.

See https://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#_implementing_a_code_valueextractor_code

import javax.validation.valueextraction.{ExtractedValue, ValueExtractor}
import javax.validation.{Validation, Validator}

object SeqValueExtractor extends ValueExtractor[Seq[_ @ExtractedValue]] {
  override def extractValues(
    originalValue: Seq[_],
    receiver: ValueExtractor.ValueReceiver
  ): Unit = {
    for ((x, i) <- originalValue.zipWithIndex) {
      receiver.indexedValue(null, i, x)
    }
  }
}

Validation
  .byDefaultProvider
  .configure
  .addValueExtractor(SeqValueExtractor)
Caused by: javax.validation.valueextraction.ValueExtractorDefinitionException: HV000203: Value extractor type io.stellargraph.storage.web.config.SeqValueExtractor$ fails to declare the extracted type parameter using @ExtractedValue.
	at org.hibernate.validator.internal.engine.valueextraction.ValueExtractorDescriptor.getExtractedTypeParameter(ValueExtractorDescriptor.java:95)
	at org.hibernate.validator.internal.engine.valueextraction.ValueExtractorDescriptor.<init>(ValueExtractorDescriptor.java:49)
	at org.hibernate.validator.internal.engine.ConfigurationImpl.addValueExtractor(ConfigurationImpl.java:219)
	at org.hibernate.validator.internal.engine.ConfigurationImpl.addValueExtractor(ConfigurationImpl.java:68)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants