jpa-spec
  1. jpa-spec
  2. JPA_SPEC-56

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

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None

      Description

      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.

        Activity

        Hide
        neilstockton added a comment -

        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).

        Show
        neilstockton added a comment - 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).
        Hide
        Xavier Dury added a comment -

        Well, you can always do something like this:

        public @interface Convert {
        
          interface NoConversionAttributeConverter extends AttributeConverter<Object, Object> {}
        
          Class<? extends AttributeConverter<?, ?>>converter() default NoConversionAttributeConverter.class;
          ...
        }
        
        Show
        Xavier Dury added a comment - Well, you can always do something like this: public @ interface Convert { interface NoConversionAttributeConverter extends AttributeConverter< Object , Object > {} Class <? extends AttributeConverter<?, ?>>converter() default NoConversionAttributeConverter.class; ... }

          People

          • Assignee:
            Unassigned
            Reporter:
            Nick Williams
          • Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:

              Time Tracking

              Estimated:
              Original Estimate - 1 hour
              1h
              Remaining:
              Remaining Estimate - 1 hour
              1h
              Logged:
              Time Spent - Not Specified
              Not Specified