javaserverfaces
  1. javaserverfaces
  2. JAVASERVERFACES-89

HtmlResponseWriter.writeAttribute() throws NPE for null values

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 1.1_01
    • Fix Version/s: 1.2
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      89

      Description

      The Javadoc for ResponseWriter.writeAttribute() notes that NullPointerException
      is thrown if name is null. Quite deliberately, it does not state that an NPE
      should be thrown if value is null (the proper behavior is a no-op). This saves
      renderer authors a lot of tedious "if (someAttrValue != null)" code.

      However, HtmlResponseWriter.writeAttribute() has some different Javadoc, and
      incorrectly throws an NPE if value is null.

      The spec for ResponseWriter.writeAttribute() should be clarified that null is a
      legit value (and a no-op), and HtmlResponseWriter should be fixed.

        Activity

        Hide
        jayashri added a comment -

        Index: src/com/sun/faces/renderkit/html_basic/HtmlResponseWriter.java
        ===================================================================
        RCS file:
        /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/renderkit/html_basic/HtmlResponseWriter.java,v
        retrieving revision 1.17
        diff -u -r1.17 HtmlResponseWriter.java
        — src/com/sun/faces/renderkit/html_basic/HtmlResponseWriter.java 16 Dec 2004
        17:56:37 -0000 1.17
        +++ src/com/sun/faces/renderkit/html_basic/HtmlResponseWriter.java 8 Mar 2005
        23:32:21 -0000
        @@ -239,14 +239,16 @@

        • @throws IllegalStateException if this method is called when there
        • is no currently open element
        • @throws IOException if an input/output error occurs
        • * @throws NullPointerException if <code>name</code> or
        • * <code>value</code> is <code>null</code>
          + * @throws NullPointerException if <code>name</code> is <code>null</code>
          */
          public void writeAttribute(String name, Object value, String
          componentPropertyName)
          throws IOException {
        • if (name == null || value == null) {
          + if (name == null) { throw new NullPointerException(Util.getExceptionMessageString( Util.NULL_PARAMETERS_ERROR_MESSAGE_ID)); + }

          + if ( value == null )

          { + value=""; }

          Adam's comments:

        > M src/com/sun/faces/renderkit/html_basic/HtmlResponseWriter.java
        > Fix for JSFRI 89
        > writeAttribute() method should not throw an exception if "value" is
        > null
        > public void writeAttribute(String name, Object value, String
        > componentPropertyName)
        > throws IOException {
        > - if (name == null || value == null) {
        > + if (name == null)

        { > throw new > NullPointerException(Util.getExceptionMessageString( > Util.NULL_PARAMETERS_ERROR_MESSAGE_ID)); > + }

        > + if ( value == null )

        { > + value=""; > }

        This should simply be "if (value == null)

        { return; }

        "; that is,
        it should write nothing, not attr="".

        Fix checked in after applying Adam's comments. Thanks, Adam

        Show
        jayashri added a comment - Index: src/com/sun/faces/renderkit/html_basic/HtmlResponseWriter.java =================================================================== RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/renderkit/html_basic/HtmlResponseWriter.java,v retrieving revision 1.17 diff -u -r1.17 HtmlResponseWriter.java — src/com/sun/faces/renderkit/html_basic/HtmlResponseWriter.java 16 Dec 2004 17:56:37 -0000 1.17 +++ src/com/sun/faces/renderkit/html_basic/HtmlResponseWriter.java 8 Mar 2005 23:32:21 -0000 @@ -239,14 +239,16 @@ @throws IllegalStateException if this method is called when there is no currently open element @throws IOException if an input/output error occurs * @throws NullPointerException if <code>name</code> or * <code>value</code> is <code>null</code> + * @throws NullPointerException if <code>name</code> is <code>null</code> */ public void writeAttribute(String name, Object value, String componentPropertyName) throws IOException { if (name == null || value == null) { + if (name == null) { throw new NullPointerException(Util.getExceptionMessageString( Util.NULL_PARAMETERS_ERROR_MESSAGE_ID)); + } + if ( value == null ) { + value=""; } Adam's comments: > M src/com/sun/faces/renderkit/html_basic/HtmlResponseWriter.java > Fix for JSFRI 89 > writeAttribute() method should not throw an exception if "value" is > null > public void writeAttribute(String name, Object value, String > componentPropertyName) > throws IOException { > - if (name == null || value == null) { > + if (name == null) { > throw new > NullPointerException(Util.getExceptionMessageString( > Util.NULL_PARAMETERS_ERROR_MESSAGE_ID)); > + } > + if ( value == null ) { > + value=""; > } This should simply be "if (value == null) { return; } "; that is, it should write nothing, not attr="". Fix checked in after applying Adam's comments. Thanks, Adam
        Hide
        jayashri added a comment -

        Fix checked in.

        Show
        jayashri added a comment - Fix checked in.
        Hide
        Manfred Riem added a comment -

        Closing issue out

        Show
        Manfred Riem added a comment - Closing issue out

          People

          • Assignee:
            jayashri
            Reporter:
            adamwiner
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: