Line numbers reported in Exceptions are Zero based, should be 1 based
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 5d88f71..338d1d5 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -7,6 +7,9 @@
</properties>
<body>
<release version="1.5" date="in Mercurial" description="development: improve performance">
+ <action dev="py4fun" type="fix" issue="24" due-to="shrode">
+ Line numbers reported in Exceptions are Zero based, should be 1 based (2009-10-12)
+ </action>
<action dev="py4fun" type="fix" issue="21" due-to="ashwin.jayaprakash">
Support arrays of reference types as JavaBean properties (2009-09-22)
</action>
diff --git a/src/main/java/org/yaml/snakeyaml/error/Mark.java b/src/main/java/org/yaml/snakeyaml/error/Mark.java
index 5d921a2..3cfd43e 100644
--- a/src/main/java/org/yaml/snakeyaml/error/Mark.java
+++ b/src/main/java/org/yaml/snakeyaml/error/Mark.java
@@ -94,9 +94,9 @@
StringBuffer where = new StringBuffer(" in \"");
where.append(name);
where.append("\", line ");
- where.append(line);
+ where.append(line + 1);
where.append(", column ");
- where.append(column);
+ where.append(column + 1);
if (snippet != null) {
where.append(":\n");
where.append(snippet);
@@ -108,10 +108,16 @@
return name;
}
+ /**
+ * starts with 0
+ */
public int getLine() {
return line;
}
+ /**
+ * starts with 0
+ */
public int getColumn() {
return column;
}
diff --git a/src/test/java/org/yaml/snakeyaml/error/MarkTest.java b/src/test/java/org/yaml/snakeyaml/error/MarkTest.java
index 60157d3..6b73033 100644
--- a/src/test/java/org/yaml/snakeyaml/error/MarkTest.java
+++ b/src/test/java/org/yaml/snakeyaml/error/MarkTest.java
@@ -29,7 +29,7 @@
public void testToString() {
Mark mark = new Mark("test1", 0, 0, 0, "*The first line.\nThe last line.", 0);
String[] lines = mark.toString().split("\n");
- assertEquals(" in \"test1\", line 0, column 0:", lines[0]);
+ assertEquals(" in \"test1\", line 1, column 1:", lines[0]);
assertEquals("*The first line.", lines[1].trim());
assertEquals("^", lines[2].trim());
}
diff --git a/src/test/java/org/yaml/snakeyaml/issues/issue24/LineNumberTest.java b/src/test/java/org/yaml/snakeyaml/issues/issue24/LineNumberTest.java
new file mode 100644
index 0000000..58f2ff7
--- /dev/null
+++ b/src/test/java/org/yaml/snakeyaml/issues/issue24/LineNumberTest.java
@@ -0,0 +1,41 @@
+/**
+ * Copyright (c) 2008-2009 Andrey Somov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.yaml.snakeyaml.issues.issue24;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.yaml.snakeyaml.Util;
+import org.yaml.snakeyaml.Yaml;
+
+/**
+ * to test http://code.google.com/p/snakeyaml/issues/detail?id=24
+ */
+public class LineNumberTest extends TestCase {
+ public void test1() throws IOException {
+ String resource = Util.getLocalResource("issues/issue24-1.yaml");
+ // System.out.println(resource);
+ Yaml yaml = new Yaml();
+ try {
+ yaml.load(resource);
+ fail();
+ } catch (Exception e) {
+ assertTrue(e.toString(), e.toString().contains("line 3"));
+ assertTrue(e.toString(), e.toString().contains("column 12"));
+ }
+ }
+}
diff --git a/src/test/resources/issues/issue24-1.yaml b/src/test/resources/issues/issue24-1.yaml
new file mode 100644
index 0000000..e9b4a6f
--- /dev/null
+++ b/src/test/resources/issues/issue24-1.yaml
@@ -0,0 +1,4 @@
+pop : {
+ banana: coconut
+ peppery: salty
+ }