Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 85c24622d1543856136405abf2e110974b76be95 1 parent b74ea38
@happygiraffe authored
View
5 NEWS.markdown
@@ -1,6 +1,11 @@
Revision history for jslint4java
================================
+1.4.1 (2010-08-05)
+------------------
+
+ * issue 40: StringIndexOutOfBoundsException on XmlResultFormatter.
+
1.4 (2010-07-27)
----------------
View
9 jslint4java-ant/src/main/java/com/googlecode/jslint4java/ant/XmlResultFormatter.java
@@ -37,12 +37,15 @@
private final StringBuilder sb = new StringBuilder();
private OutputStream out;
+ @Override
public void begin() {
if (out == null) {
throw new BuildException("must specify destFile for xml output");
}
// Clear, just in case this object gets reused.
- sb.delete(0, sb.length() - 1);
+ if (sb.length() > 0) {
+ sb.delete(0, sb.length() - 1);
+ }
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
sb.append("<jslint>\n");
}
@@ -52,6 +55,7 @@ public void begin() {
*
* @see com.googlecode.jslint4java.ant.ResultFormatter#end()
*/
+ @Override
public void end() {
sb.append("</jslint>");
Writer w = null;
@@ -72,10 +76,12 @@ public void end() {
* <i>line</i>, <i>char</i>, <i>reason</i> and <i>evidence</i> attributes. An element will be
* created for all files, regardless of any issues being uncovered.
*/
+ @Override
public void output(JSLintResult result) {
sb.append(form.format(result));
}
+ @Override
public void setFile(File file) {
try {
out = new FileOutputStream(file);
@@ -84,6 +90,7 @@ public void setFile(File file) {
}
}
+ @Override
public void setStdout(OutputStream defaultOutputStream) {
// Ignore, we never want to write to stdout.
}
View
35 jslint4java-ant/src/test/java/com/googlecode/jslint4java/ant/XmlResultFormatterTest.java
@@ -0,0 +1,35 @@
+package com.googlecode.jslint4java.ant;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+
+import java.io.File;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import com.googlecode.jslint4java.JSLintResult;
+
+
+public class XmlResultFormatterTest {
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder();
+
+ private final XmlResultFormatter formatter = new XmlResultFormatter();
+
+ private void runFormatter(File output, JSLintResult result) {
+ formatter.setFile(output);
+ formatter.begin();
+ formatter.output(result);
+ formatter.end();
+ }
+
+ @Test
+ public void testXmlOutput() throws Exception {
+ JSLintResult result = new JSLintResult.ResultBuilder("main.js").build();
+ File output = folder.newFile("report.xml");
+ runFormatter(output, result);
+ assertThat(output.exists(), is(true));
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.