Bug 35252

Summary: jasper2 produced malformed expanded XML view
Product: Tomcat 5 Reporter: Rahul <akolkar>
Component: JasperAssignee: Tomcat Developers Mailing List <dev>
Severity: normal    
Priority: P2    
Version: 5.5.12   
Target Milestone: ---   
Hardware: All   
OS: All   

Description Rahul 2005-06-07 07:36:43 UTC
The FirstPassVisitor in org.apache.jasper.compiler.PageDataImpl adds all 
attributes (except "version") of jsp:root elements of included JSPs to 
jsp:root of expanded XML view. The expanded XML view is thus, often malformed.

Any entity, such as a TagLibraryValidator, that tries to subsequently parse 
the malformed expanded XML view, fails. For example:

main.jspx (using Jakarta Taglibs "standard" JSTL impl):
<?xml version="1.0" encoding="UTF-8"?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" 
 xmlns:c="http://java.sun.com/jsp/jstl/core" version="2.0" >
    <jsp:directive.include file="one.jspx"/>

where one.jspx is:
<?xml version="1.0" encoding="UTF-8"?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0" />

org.apache.jasper.JasperException: <h3>Validation error messages from 
TagLibraryValidator for c</h3><p>null: org.xml.sax.SAXParseException: 
Attribute "jsp" bound to namespace "http://www.w3.org/2000/xmlns/" was already 
specified for element "jsp:root".</p>

as, in this scenario, attribute xmlns:jsp gets added twice.

[Problem reported by "Dino Klein" <zagzag@speakeasy.net> on taglibs-dev@j.a.o]

I'm proposing a patch that causes FirstPassVisitor to only add those 
attributes to the jsp:root of the expanded XML view that have not been already 

Index: PageDataImpl.java
RCS file: /usr/local/cvsroot/apache/jakarta-tomcat-5.0.28-src/jakarta-tomcat-
retrieving revision 1.1
diff -c -r1.1 PageDataImpl.java
*** PageDataImpl.java	7 Jun 2005 02:29:52 -0000	1.1
--- PageDataImpl.java	7 Jun 2005 02:33:19 -0000
*** 205,218 ****
  	    if (attrs != null) {
  		int len = attrs.getLength();
  		for (int i=0; i<len; i++) {
! 		    if ("version".equals(attrs.getQName(i))) {
! 		    rootAttrs.addAttribute(attrs.getURI(i),
! 					   attrs.getQName(i),
--- 205,221 ----
  	    if (attrs != null) {
  		int len = attrs.getLength();
  		for (int i=0; i<len; i++) {
! 		    String qName = attrs.getQName(i);
! 		    if ("version".equals(qName)) {
! 		    if (rootAttrs.getIndex(qName) == -1) {
! 		    	rootAttrs.addAttribute(attrs.getURI(i),
! 					   qName,
+ 		    }
Comment 1 Dino 2005-10-16 06:58:55 UTC
This is still a problem with 5.5.12.
Perhaps the version in this bug should be changed in order to reflect that.
Comment 2 Yoav Shapira 2005-10-16 07:04:07 UTC
Updated versions (which by the way anyone can do), will fix right now.
Comment 3 Yoav Shapira 2005-10-16 07:20:42 UTC
Comment 4 n nemer 2006-01-27 21:49:34 UTC
is this really fixed?  i have tomcat 5.5.15 and get the exact same error:  
org.apache.jasper.JasperException: Error on line 1 of document  : Attribute
"star" bound to namespace "http://www.w3.org/2000/xmlns/" was already specified
for element "star:content-block". Nested exception: Attribute "star" bound to
namespace "http://www.w3.org/2000/xmlns/" was already specified for element

Comment 5 Fabio Grassi 2006-04-27 14:21:16 UTC
It looks fixed in 5.5.16. Is it really? Should the bug be closed?
Comment 6 Mark Thomas 2006-10-01 20:46:00 UTC
The duplicate has more info on how to reproduce.

*** This bug has been marked as a duplicate of 39557 ***