9 Replies Latest reply on Aug 11, 2005 12:10 AM by starksm64

    Inconsistency with primitive wrappers and prop-editors

    sebersole

      Currently the JBoss property editors for the primitive wrapper types never allow a null representation. This seems very inconsistent to me, as developers tend to choose java.lang.Boolean over boolean because they want/allow null values.

      The needed change is pretty simple. Assuming that we decide "", "null", and "(String)null" all represent valid null values, just change (BooleanEditor as example):

      public void setAsText(final String text)
      {
       Object newValue = Boolean.valueOf(text);
       setValue(newValue);
      }
      

      to :
      protected static final String NULL = "null";
      public void setAsText(final String text) {
       if ( isNull( text ) ) {
       setValue( null );
       }
       else {
       setValue( Boolean.valueOf( text ) );
       }
      }
      protected boolean isNull(final String text) {
       if ( text == null ) {
       return true;
       }
       else {
       final String trimmed = text.trim().toLowerCase();
       return trimmed.size() == 0 || NULL.equals( trimmed );
       }
      }
      


      However, I am not sure whether there is existing code which exposes java.lang.Boolean attributes and relies on this behavior of never getting null values. Not sure why they expose the wrapper type anyway though if that is the case, but that's a different topic :)

      As of right now, the implication of choosing to expose MBean's with a type-safe interface with any of these primitive wrappers means that the MBean will currently never get back null values.