From b59648d60599bc197de618af5406c5e46978bbda Mon Sep 17 00:00:00 2001 From: Rick Giles Date: Sat, 10 May 2003 15:17:54 +0000 Subject: [PATCH] Added line and column numbers to configuration parse exceptions (request 714962). --- docs/releasenotes.html | 4 ++++ .../puppycrawl/tools/checkstyle/ConfigurationLoader.java | 6 ++++++ .../tools/checkstyle/ConfigurationLoaderTest.java | 8 ++++---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/releasenotes.html b/docs/releasenotes.html index 5e617d58d..4b41a1c25 100644 --- a/docs/releasenotes.html +++ b/docs/releasenotes.html @@ -127,6 +127,10 @@ to "error" element of XMLLogger output (request 686336). +
  • Added line and column numbers + to configuration parse exceptions + (request 714962).
  • +

    diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/ConfigurationLoader.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/ConfigurationLoader.java index 7ff8f8112..0b9b4b57e 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/ConfigurationLoader.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/ConfigurationLoader.java @@ -36,6 +36,7 @@ import com.puppycrawl.tools.checkstyle.api.Configuration; import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; /** * Loads a configuration from a standard configuration XML file. @@ -221,6 +222,11 @@ public final class ConfigurationLoader throw new CheckstyleException( "unable to parse " + aConfig, e); } + catch (SAXParseException e) { + throw new CheckstyleException("unable to parse " + + aConfig + " - " + e.getMessage() + ":" + e.getLineNumber() + + ":" + e.getColumnNumber(), e); + } catch (SAXException e) { throw new CheckstyleException("unable to parse " + aConfig + " - " + e.getMessage(), e); diff --git a/src/tests/com/puppycrawl/tools/checkstyle/ConfigurationLoaderTest.java b/src/tests/com/puppycrawl/tools/checkstyle/ConfigurationLoaderTest.java index 86b64dad8..5dd886edc 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/ConfigurationLoaderTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/ConfigurationLoaderTest.java @@ -47,7 +47,7 @@ public class ConfigurationLoaderTest extends TestCase assertTrue( ex.getMessage().endsWith( "Attribute \"name\" is required and must be specified " - + "for element type \"property\".")); + + "for element type \"property\".:8:41")); } } @@ -61,7 +61,7 @@ public class ConfigurationLoaderTest extends TestCase assertTrue( ex.getMessage().endsWith( "Attribute \"value\" is required and must be specified " - + "for element type \"property\".")); + + "for element type \"property\".:8:41")); } } @@ -75,7 +75,7 @@ public class ConfigurationLoaderTest extends TestCase assertTrue( ex.getMessage().endsWith( "Attribute \"name\" is required and must be specified " - + "for element type \"module\".")); + + "for element type \"module\".:7:23")); } } @@ -89,7 +89,7 @@ public class ConfigurationLoaderTest extends TestCase assertTrue( ex.getMessage().endsWith( "Document root element \"property\", must match DOCTYPE " - + "root \"module\".")); + + "root \"module\".:7:38")); } }