dev@javaserverfaces.java.net

Review: Fix for JSF RI 85, 89

From: Jayashri Visvanathan <Jayashri.Visvanathan_at_Sun.COM>
Date: Tue, 08 Mar 2005 15:52:57 -0800

M src/com/sun/faces/application/ApplicationImpl.java
  Fix for JSFRI 85. Throw FacesException if a converter could not
  be created by createConverter() (that takes a converter class
  as an argument) as required by the Spec.

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

M test/com/sun/faces/convert/TestConverters.java
M test/com/sun/faces/renderkit/html_basic/TestHtmlResponseWriter.java
  update the tests for the above changes.

Adam, I would appreciate if you can a do quick review of the changes.
Thanks
-Jayashri


Index: src/com/sun/faces/application/ApplicationImpl.java
===================================================================
RCS file: /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/application/ApplicationImpl.java,v
retrieving revision 1.57
diff -u -r1.57 ApplicationImpl.java
--- src/com/sun/faces/application/ApplicationImpl.java 28 Feb 2005 18:48:20 -0000 1.57
+++ src/com/sun/faces/application/ApplicationImpl.java 8 Mar 2005 23:32:21 -0000
@@ -440,23 +440,37 @@
             message = message +" targetClass " + targetClass;
             throw new NullPointerException(message);
         }
+ Converter result = createConverterBasedOnClass(targetClass);
+ if (result == null) {
+ if (log.isErrorEnabled()) {
+ log.error("Couldn't instantiate converter of the type " +
+ targetClass.getName());
+ }
+ Object[] params = {targetClass.getName()};
+ throw new FacesException(Util.getExceptionMessageString(
+ Util.NAMED_OBJECT_NOT_FOUND_ERROR_MESSAGE_ID, params));
+ }
+ return result;
+ }
+
+ protected Converter createConverterBasedOnClass(Class targetClass) {
+
         Converter returnVal = (Converter) newThing(targetClass,
                                                    converterTypeMap);
-
         if (returnVal != null) {
             if (log.isTraceEnabled()) {
                 log.trace("Created converter of type " +
                           returnVal.getClass().getName());
             }
             return returnVal;
- }
+ }
 
         //Search for converters registered to interfaces implemented by
         //targetClass
         Class[] interfaces = targetClass.getInterfaces();
         if (interfaces != null) {
             for (int i = 0; i < interfaces.length; i++) {
- returnVal = createConverter(interfaces[i]);
+ returnVal = createConverterBasedOnClass(interfaces[i]);
                 if (returnVal != null) {
                     if (log.isTraceEnabled()) {
                         log.trace("Created converter of type " +
@@ -470,7 +484,7 @@
         //Search for converters registered to superclasses of targetClass
         Class superclass = targetClass.getSuperclass();
         if (superclass != null) {
- returnVal = createConverter(superclass);
+ returnVal = (Converter) createConverterBasedOnClass(superclass);
             if (returnVal != null) {
                 if (log.isTraceEnabled()) {
                     log.trace("Created converter of type " +
@@ -478,8 +492,7 @@
                 }
                 return returnVal;
             }
- }
-
+ }
         return returnVal;
     }
 
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="";
         }
 
         Class valueClass = value.getClass();
Index: test/com/sun/faces/convert/TestConverters.java
===================================================================
RCS file: /cvs/javaserverfaces-sources/jsf-ri/test/com/sun/faces/convert/TestConverters.java,v
retrieving revision 1.31
diff -u -r1.31 TestConverters.java
--- test/com/sun/faces/convert/TestConverters.java 3 Jan 2005 18:16:52 -0000 1.31
+++ test/com/sun/faces/convert/TestConverters.java 8 Mar 2005 23:32:23 -0000
@@ -796,7 +796,11 @@
         application.addConverter(java.util.AbstractCollection.class,
                                  "javax.faces.convert.DateTimeConverter");
         converter = null;
- converter = application.createConverter(java.util.HashSet.class);
+ try {
+ converter = application.createConverter(java.util.HashSet.class);
+ } catch (javax.faces.FacesException fe) {
+
+ }
         assertTrue(converter != null);
 
 
Index: test/com/sun/faces/renderkit/html_basic/TestHtmlResponseWriter.java
===================================================================
RCS file: /cvs/javaserverfaces-sources/jsf-ri/test/com/sun/faces/renderkit/html_basic/TestHtmlResponseWriter.java,v
retrieving revision 1.13
diff -u -r1.13 TestHtmlResponseWriter.java
--- test/com/sun/faces/renderkit/html_basic/TestHtmlResponseWriter.java 26 Feb 2004 20:34:38 -0000 1.13
+++ test/com/sun/faces/renderkit/html_basic/TestHtmlResponseWriter.java 8 Mar 2005 23:32:24 -0000
@@ -316,7 +316,7 @@
         } catch (NullPointerException npe) {
             exceptionThrown = true;
         }
- assertTrue(exceptionThrown);
+ assertTrue(!exceptionThrown);
         exceptionThrown = false;
         try {
             writer.writeAttribute(null, "bar", null);