DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://issues.apache.org/bugzilla/show_bug.cgi?id=30660>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=30660 Vague parse error when using namespaces Summary: Vague parse error when using namespaces Product: Ant Version: 1.7Alpha (nightly) Platform: PC OS/Version: Windows XP Status: NEW Severity: Minor Priority: Other Component: Core AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] I was playing around trying to learn how to use an antlib when I tried this build file. <?xml version="1.0" encoding="UTF-8"?> <project basedir="." default="msg" xmlns="antlib:any.resource"> <target name="msg"> <echo message="Echo."/> </target> </project> The build failed with this error: Unexpected element "project" project at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:223) at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:132) at org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:92) at org.apache.tools.ant.Main.runBuild(Main.java:658) at org.apache.tools.ant.Main.startAnt(Main.java:188) at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196) at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55) Being completely confused by the 'Unexpected element "project" project', I started digging at the code. I found two problems that contributed to the uninformative message. 1) In ProjectHelper2.parse, there is a catch block for SAXParseException. This block extracts the cause exception from the SAXParseException using "exc.getException ()" then creates a BuildException with that cause exception. In this particular case, "exc.getException()" returned null so the BuildException had no cause. 2) The actual exception message comes from ProjectHelper2.MainHandler.onStartChild. The qname and name parameters supplied by the SAX parser are identical as my xmlns attribute did not set a namespace. I believe that the first problem can be fixed by using the SAXParseException as the cause when it does not itself contain a cause exception. As for the message text, it seems appropriate to display the namespace URIs when the qname and name are otherwise identical. I've attached a patch that implements both of these changes. Using this patch, the original exception changed into the following. Unexpected element "{antlib:any.resource}project" {antlib:org.apache.tools.ant}project at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:225) at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:132) at org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:92) at org.apache.tools.ant.Main.runBuild(Main.java:658) at org.apache.tools.ant.Main.startAnt(Main.java:188) at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196) at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55) Caused by: org.xml.sax.SAXParseException: Unexpected element "{antlib:any.resource}project" {antlib:org.apache.tools.ant}project at org.apache.tools.ant.helper.ProjectHelper2$MainHandler.onStartChild(ProjectHelper2.java:542) at org.apache.tools.ant.helper.ProjectHelper2$RootHandler.startElement(ProjectHelper2.java:437) at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source) at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source) at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:209) ... --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]