Browse Source

Better reporting of errors when JAXP not present.

Catch NoClassDefFoundError as well as NullPointerException and
emit a more meaningful error message.

Change BuildException to accept Errors as well as Exceptions
as cause.

Submitted by:	Stefan Bodewig <bodewig@bost.de>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267682 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 25 years ago
parent
commit
4f8bb2ee77
2 changed files with 13 additions and 8 deletions
  1. +6
    -6
      src/main/org/apache/tools/ant/BuildException.java
  2. +7
    -2
      src/main/org/apache/tools/ant/Main.java

+ 6
- 6
src/main/org/apache/tools/ant/BuildException.java View File

@@ -63,7 +63,7 @@ package org.apache.tools.ant;
public class BuildException extends RuntimeException { public class BuildException extends RuntimeException {


/** Exception that might have caused this one. */ /** Exception that might have caused this one. */
private Exception cause;
private Throwable cause;


/** Location in the build file where the exception occured */ /** Location in the build file where the exception occured */
private Location location = Location.UNKNOWN_LOCATION; private Location location = Location.UNKNOWN_LOCATION;
@@ -89,10 +89,10 @@ public class BuildException extends RuntimeException {
* Constructs an exception with the given message and exception as * Constructs an exception with the given message and exception as
* a root cause. * a root cause.
* @param msg Description of or information about the exception. * @param msg Description of or information about the exception.
* @param cause Exception that might have cause this one.
* @param cause Throwable that might have cause this one.
*/ */


public BuildException(String msg, Exception cause) {
public BuildException(String msg, Throwable cause) {
super(msg); super(msg);
this.cause = cause; this.cause = cause;
} }
@@ -105,7 +105,7 @@ public class BuildException extends RuntimeException {
* @param location Location in the project file where the error occured. * @param location Location in the project file where the error occured.
*/ */


public BuildException(String msg, Exception cause, Location location) {
public BuildException(String msg, Throwable cause, Location location) {
this(msg, cause); this(msg, cause);
this.location = location; this.location = location;
} }
@@ -115,7 +115,7 @@ public class BuildException extends RuntimeException {
* @param cause Exception that might have caused this one. * @param cause Exception that might have caused this one.
*/ */


public BuildException(Exception cause) {
public BuildException(Throwable cause) {
super(cause.toString()); super(cause.toString());
this.cause = cause; this.cause = cause;
} }
@@ -135,7 +135,7 @@ public class BuildException extends RuntimeException {
/** /**
* Returns the nested exception. * Returns the nested exception.
*/ */
public Exception getException() {
public Throwable getException() {
return cause; return cause;
} }




+ 7
- 2
src/main/org/apache/tools/ant/Main.java View File

@@ -222,12 +222,17 @@ public class Main {
try { try {
try { try {
Class.forName("javax.xml.parsers.SAXParserFactory"); Class.forName("javax.xml.parsers.SAXParserFactory");
ProjectHelper.configureProject(project, buildFile);
} catch (NoClassDefFoundError ncdfe) {
throw new BuildException("No JAXP compliant XML parser found. See http://java.sun.com/xml for the\nreference implementation.", ncdfe);
} catch (ClassNotFoundException cnfe) { } catch (ClassNotFoundException cnfe) {
throw new BuildException(cnfe);
throw new BuildException("No JAXP compliant XML parser found. See http://java.sun.com/xml for the\nreference implementation.", cnfe);
} catch (NullPointerException npe) {
throw new BuildException("No JAXP compliant XML parser found. See http://java.sun.com/xml for the\nreference implementation.", npe);
} }
ProjectHelper.configureProject(project, buildFile);
} catch (BuildException be) { } catch (BuildException be) {
System.out.println("\nBUILD CONFIG ERROR\n"); System.out.println("\nBUILD CONFIG ERROR\n");
System.out.println(be.getMessage());
if (be.getException() == null) { if (be.getException() == null) {
System.out.println(be.toString()); System.out.println(be.toString());
} else { } else {


Loading…
Cancel
Save