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

@Convert annotation's converter property should be Class<? extends AttributeConverter>, not Class (unsafe) #56

Closed
lukasj opened this issue May 4, 2013 · 6 comments · Fixed by #487

Comments

@lukasj
Copy link
Contributor

lukasj commented May 4, 2013

Currently, the converter property for the @convert annotation is declared as follows:

Class converter() default void.class;

However, along with just generally being unsafe ("safe" use would be Class<?>), this does not properly restrict the set of classes that can be specified. My understanding is that this MUST be a class that implements javax.persistence.AttributeConverter. Therefore, the converter property should be specified like so:

Class<? extends AttributeConverter> converter() default void.class;

With this change, the developer will know at compile time if he has specified an incorrect class. Without this change, the developer will not know until he gets a runtime error, which is seriously less desirable.

@lukasj
Copy link
Contributor Author

lukasj commented May 4, 2013

@glassfishrobot Commented
Reported by beamerblvd

@lukasj
Copy link
Contributor Author

lukasj commented May 17, 2015

@glassfishrobot Commented
neilstockton said:
You can't do that.

Class<? extends AttributeConverter> converter() default void.class;
would not compile. "void.class" is not castable to the generic form (but is to the non-generic form, hence probably why they did it).

@lukasj
Copy link
Contributor Author

lukasj commented Dec 10, 2015

@glassfishrobot Commented
kalgon said:
Well, you can always do something like this:

public @interface Convert {

  interface NoConversionAttributeConverter extends AttributeConverter<Object, Object> {}

  Class<? extends AttributeConverter<?, ?>>converter() default NoConversionAttributeConverter.class;
  ...
}

@lukasj
Copy link
Contributor Author

lukasj commented May 5, 2017

@glassfishrobot Commented
This issue was imported from java.net JIRA JPA_SPEC-56

@lukasj
Copy link
Contributor Author

lukasj commented Aug 31, 2018

@gavinking
Copy link
Contributor

Fixed in #487.

@lukasj lukasj added this to To do in 3.2.0 via automation Aug 25, 2023
3.2.0 automation moved this from To do to Done Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
3.2.0
Done
Development

Successfully merging a pull request may close this issue.

2 participants