ClassCastException in XFormsModelSubmission

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

ClassCastException in XFormsModelSubmission

Daniel E. Renfer
Erik and Alex,

Recently I was step debugging through the XForms submission code and I
ran across a section where the header values were being incorrectly cast
to a List as opposed to a String. Checking the latest from CVS, I see
that Alex added a note last month indicating that this was failing in
some cases.

My question is, are you actually seeing this succeeding in any cases? It
appears that this is a reproduction of the same error that occurred
further up in the code. (Where this block was originally copied from)
Looking at line 692 you can see that Erik fixed this a year ago.

In the event that it always returns a String and never a List, I've
attached a patch for you.

Share and Enjoy,
Daniel E. Renfer
http://kronkltd.net/

### Eclipse Workspace Patch 1.0
#P orbeon
Index: src/java/org/orbeon/oxf/xforms/XFormsModelSubmission.java
===================================================================
RCS file: /cvsroot/ops/orbeon/src/java/org/orbeon/oxf/xforms/XFormsModelSubmission.java,v
retrieving revision 1.137
diff -u -r1.137 XFormsModelSubmission.java
--- src/java/org/orbeon/oxf/xforms/XFormsModelSubmission.java 9 Jul 2007 14:10:24 -0000 1.137
+++ src/java/org/orbeon/oxf/xforms/XFormsModelSubmission.java 21 Jul 2007 21:02:42 -0000
@@ -805,13 +805,10 @@
                                 for (Iterator i = connectionResult.resultHeaders.entrySet().iterator(); i.hasNext();) {
                                     final Map.Entry currentEntry = (Map.Entry) i.next();
                                     final String headerName = (String) currentEntry.getKey();
-                                    // TODO: In some cases it seems this returns a String, not a List
-                                    final List headerValues = (List) currentEntry.getValue();
+                                    final String headerValue = (String) currentEntry.getValue();
 
-                                    if (headerName != null && headerValues != null) {
-                                        for (Iterator j = headerValues.iterator(); j.hasNext();) {
-                                            response.addHeader(headerName, (String) j.next());
-                                        }
+                                    if (headerName != null && headerValue != null) {
+                                        response.addHeader(headerName, headerValue);
                                     }
                                 }
                             }


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws

signature.asc (258 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: ClassCastException in XFormsModelSubmission

Erik Bruchez
Administrator
Daniel,

Thanks for the patch!

The issue is a funny one.

connectionResult.resultHeaders is set into places only it seems:
XFormsSubmissionUtils.doOptimized() (where it receives an empty Map) and
XFormsSubmissionUtils.doRegular(), where the result comes directly from
java.net.URLConnection.getHeaderFields().

The Javadoc for that method says in JDK 1.5.0:

"Each Map value is an unmodifiable List of Strings that represents the
corresponding field values"

So it seems reasonable to cast to a List based on the doc! But who
knows, there may be a bug downstream causing a String to be returned
from time to time. What JDK are you using?

My guess is that in some cases, there is a bug causing a String to be
returned. It would be nice to know exactly when this occurs, but for now
I have modified the code safely (I hope) to handle String as well as
List to avoid crashes.

This also fixes the "TODO" which said that the forwarding code was
duplicated.

Please let us know if you have a chance to get the latest CVS and see if
my fix works for you!

-Erik

Daniel E. Renfer wrote:

> Erik and Alex,
>
> Recently I was step debugging through the XForms submission code and I
> ran across a section where the header values were being incorrectly cast
> to a List as opposed to a String. Checking the latest from CVS, I see
> that Alex added a note last month indicating that this was failing in
> some cases.
>
> My question is, are you actually seeing this succeeding in any cases? It
> appears that this is a reproduction of the same error that occurred
> further up in the code. (Where this block was originally copied from)
> Looking at line 692 you can see that Erik fixed this a year ago.
>
> In the event that it always returns a String and never a List, I've
> attached a patch for you.
>
> Share and Enjoy,
> Daniel E. Renfer
> http://kronkltd.net/
>

--
Orbeon Forms - Web Forms for the Enterprise Done the Right Way
http://www.orbeon.com/



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: ClassCastException in XFormsModelSubmission

Daniel E. Renfer
I am using JDK 1.6.2 with Tomcat 5.5

In my testing, every time I've tested it, I've gotten back only Strings.
Of course, I haven't tested it when returning multiple headers of the
same name. Perhaps that's the case in which it would return a list?

Btw, the reason I'm delving into this area of the source code is I've
been trying to include support for the additional context information
that 1.1 specifies for xforms-error-event.[1] I'm planning on sharing my
code as soon as it's done, but I got one part working and instead of
getting a status code, i got an empty string because that line was
throwing an exception.

[1]: http://www.w3.org/TR/xforms11/#submit-evt-submit-error

Erik Bruchez wrote:

> Daniel,
>
> Thanks for the patch!
>
> The issue is a funny one.
>
> connectionResult.resultHeaders is set into places only it seems:
> XFormsSubmissionUtils.doOptimized() (where it receives an empty Map) and
> XFormsSubmissionUtils.doRegular(), where the result comes directly from
> java.net.URLConnection.getHeaderFields().
>
> The Javadoc for that method says in JDK 1.5.0:
>
> "Each Map value is an unmodifiable List of Strings that represents the
> corresponding field values"
>
> So it seems reasonable to cast to a List based on the doc! But who
> knows, there may be a bug downstream causing a String to be returned
> from time to time. What JDK are you using?
>
> My guess is that in some cases, there is a bug causing a String to be
> returned. It would be nice to know exactly when this occurs, but for now
> I have modified the code safely (I hope) to handle String as well as
> List to avoid crashes.
>
> This also fixes the "TODO" which said that the forwarding code was
> duplicated.
>
> Please let us know if you have a chance to get the latest CVS and see if
> my fix works for you!
>
> -Erik
>
> Daniel E. Renfer wrote:
>> Erik and Alex,
>>
>> Recently I was step debugging through the XForms submission code and I
>> ran across a section where the header values were being incorrectly cast
>> to a List as opposed to a String. Checking the latest from CVS, I see
>> that Alex added a note last month indicating that this was failing in
>> some cases.
>>
>> My question is, are you actually seeing this succeeding in any cases? It
>> appears that this is a reproduction of the same error that occurred
>> further up in the code. (Where this block was originally copied from)
>> Looking at line 692 you can see that Erik fixed this a year ago.
>>
>> In the event that it always returns a String and never a List, I've
>> attached a patch for you.
>>
>> Share and Enjoy,
>> Daniel E. Renfer
>> http://kronkltd.net/


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws

signature.asc (258 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: ClassCastException in XFormsModelSubmission

Erik Bruchez
Administrator
Daniel E. Renfer wrote:

> I am using JDK 1.6.2 with Tomcat 5.5
>
> In my testing, every time I've tested it, I've gotten back only Strings.
> Of course, I haven't tested it when returning multiple headers of the
> same name. Perhaps that's the case in which it would return a list?
>
> Btw, the reason I'm delving into this area of the source code is I've
> been trying to include support for the additional context information
> that 1.1 specifies for xforms-error-event.[1] I'm planning on sharing my
> code as soon as it's done, but I got one part working and instead of
> getting a status code, i got an empty string because that line was
> throwing an exception.
>
> [1]: http://www.w3.org/TR/xforms11/#submit-evt-submit-error
That would be great :-) Let us know where this is going.

Best,

-Erik

--
Orbeon Forms - Web Forms for the Enterprise Done the Right Way
http://www.orbeon.com/



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws