Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

issue 40: Check for non-empty string before deleting.

  • Loading branch information...
commit 85c24622d1543856136405abf2e110974b76be95 1 parent b74ea38
Dominic Mitchell authored August 05, 2010
5  NEWS.markdown
Source Rendered
... ...
@@ -1,6 +1,11 @@
1 1
 Revision history for jslint4java
2 2
 ================================
3 3
 
  4
+1.4.1 (2010-08-05)
  5
+------------------
  6
+
  7
+ * issue 40: StringIndexOutOfBoundsException on XmlResultFormatter.
  8
+
4 9
 1.4 (2010-07-27)
5 10
 ----------------
6 11
 
9  jslint4java-ant/src/main/java/com/googlecode/jslint4java/ant/XmlResultFormatter.java
@@ -37,12 +37,15 @@
37 37
     private final StringBuilder sb = new StringBuilder();
38 38
     private OutputStream out;
39 39
 
  40
+    @Override
40 41
     public void begin() {
41 42
         if (out == null) {
42 43
             throw new BuildException("must specify destFile for xml output");
43 44
         }
44 45
         // Clear, just in case this object gets reused.
45  
-        sb.delete(0, sb.length() - 1);
  46
+        if (sb.length() > 0) {
  47
+            sb.delete(0, sb.length() - 1);
  48
+        }
46 49
         sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
47 50
         sb.append("<jslint>\n");
48 51
     }
@@ -52,6 +55,7 @@ public void begin() {
52 55
      *
53 56
      * @see com.googlecode.jslint4java.ant.ResultFormatter#end()
54 57
      */
  58
+    @Override
55 59
     public void end() {
56 60
         sb.append("</jslint>");
57 61
         Writer w = null;
@@ -72,10 +76,12 @@ public void end() {
72 76
      * <i>line</i>, <i>char</i>, <i>reason</i> and <i>evidence</i> attributes. An element will be
73 77
      * created for all files, regardless of any issues being uncovered.
74 78
      */
  79
+    @Override
75 80
     public void output(JSLintResult result) {
76 81
         sb.append(form.format(result));
77 82
     }
78 83
 
  84
+    @Override
79 85
     public void setFile(File file) {
80 86
         try {
81 87
             out = new FileOutputStream(file);
@@ -84,6 +90,7 @@ public void setFile(File file) {
84 90
         }
85 91
     }
86 92
 
  93
+    @Override
87 94
     public void setStdout(OutputStream defaultOutputStream) {
88 95
         // Ignore, we never want to write to stdout.
89 96
     }
35  jslint4java-ant/src/test/java/com/googlecode/jslint4java/ant/XmlResultFormatterTest.java
... ...
@@ -0,0 +1,35 @@
  1
+package com.googlecode.jslint4java.ant;
  2
+
  3
+import static org.hamcrest.CoreMatchers.*;
  4
+import static org.junit.Assert.*;
  5
+
  6
+import java.io.File;
  7
+
  8
+import org.junit.Rule;
  9
+import org.junit.Test;
  10
+import org.junit.rules.TemporaryFolder;
  11
+
  12
+import com.googlecode.jslint4java.JSLintResult;
  13
+
  14
+
  15
+public class XmlResultFormatterTest {
  16
+    @Rule
  17
+    public TemporaryFolder folder = new TemporaryFolder();
  18
+
  19
+    private final XmlResultFormatter formatter = new XmlResultFormatter();
  20
+
  21
+    private void runFormatter(File output, JSLintResult result) {
  22
+        formatter.setFile(output);
  23
+        formatter.begin();
  24
+        formatter.output(result);
  25
+        formatter.end();
  26
+    }
  27
+
  28
+    @Test
  29
+    public void testXmlOutput() throws Exception {
  30
+        JSLintResult result = new JSLintResult.ResultBuilder("main.js").build();
  31
+        File output = folder.newFile("report.xml");
  32
+        runFormatter(output, result);
  33
+        assertThat(output.exists(), is(true));
  34
+    }
  35
+}

0 notes on commit 85c2462

Please sign in to comment.
Something went wrong with that request. Please try again.