[testng] 76/355: testng-562 testNG not creating HTML report Fix NPE in XMLStringBuffer.java Add corresponding Nullable annotations
Eugene Zhukov
eugene-guest at moszumanska.debian.org
Tue Aug 18 10:19:49 UTC 2015
This is an automated email from the git hooks/post-receive script.
eugene-guest pushed a commit to annotated tag OpenBSD
in repository testng.
commit 871d87507f9bffea035e2055ac96fbe419df413f
Author: Vladislav Rassokhin <vladrassokhin at gmail.com>
Date: Sat Nov 15 08:03:20 2014 +0300
testng-562 testNG not creating HTML report
Fix NPE in XMLStringBuffer.java
Add corresponding Nullable annotations
---
.../java/org/testng/reporters/XMLStringBuffer.java | 45 ++++++++++++++--------
src/main/java/org/testng/reporters/XMLUtils.java | 27 +++++++++----
2 files changed, 48 insertions(+), 24 deletions(-)
diff --git a/src/main/java/org/testng/reporters/XMLStringBuffer.java b/src/main/java/org/testng/reporters/XMLStringBuffer.java
index 441ac6b..092c10e 100755
--- a/src/main/java/org/testng/reporters/XMLStringBuffer.java
+++ b/src/main/java/org/testng/reporters/XMLStringBuffer.java
@@ -1,5 +1,7 @@
package org.testng.reporters;
+import org.testng.internal.Nullable;
+
import java.io.Writer;
import java.util.Properties;
import java.util.Stack;
@@ -64,7 +66,7 @@ public class XMLStringBuffer {
* @param start A string of spaces indicating the indentation at which
* to start the generation.
*/
- private void init(IBuffer buffer, String start, String version, String encoding) {
+ private void init(IBuffer buffer, String start, @Nullable String version, @Nullable String encoding) {
m_buffer = buffer;
m_currentIndent = start;
if (version != null) {
@@ -80,7 +82,7 @@ public class XMLStringBuffer {
*/
public void setXmlDetails(String v, String enc) {
if (m_buffer.toString().length() != 0) {
- throw new RuntimeException("Buffer should be empty: '" + m_buffer.toString() + "'");
+ throw new IllegalStateException("Buffer should be empty: '" + m_buffer.toString() + "'");
}
m_buffer.append("<?xml version=\"" + v + "\" encoding=\"" + enc + "\"?>").append(EOL);
}
@@ -102,7 +104,7 @@ public class XMLStringBuffer {
* @param schema The schema to use (can be null or an empty string).
* @param attributes A Properties file representing the attributes (or null)
*/
- public void push(String tagName, String schema, Properties attributes) {
+ public void push(String tagName, @Nullable String schema, @Nullable Properties attributes) {
XMLUtils.xmlOpen(m_buffer, m_currentIndent, tagName + schema, attributes);
m_tagStack.push(new Tag(m_currentIndent, tagName, attributes));
m_currentIndent += DEFAULT_INDENT_INCREMENT;
@@ -115,7 +117,7 @@ public class XMLStringBuffer {
* @param tagName The name of the tag.
* @param schema The schema to use (can be null or an empty string).
*/
- public void push(String tagName, String schema) {
+ public void push(String tagName, @Nullable String schema) {
push(tagName, schema, null);
}
@@ -126,7 +128,7 @@ public class XMLStringBuffer {
* @param tagName The name of the tag.
* @param attributes A Properties file representing the attributes (or null)
*/
- public void push(String tagName, Properties attributes) {
+ public void push(String tagName, @Nullable Properties attributes) {
push(tagName, "", attributes);
}
@@ -136,6 +138,12 @@ public class XMLStringBuffer {
private Properties createProperties(String[] attributes) {
Properties result = new Properties();
+ if (attributes == null) {
+ return result;
+ }
+ if (attributes.length % 2 != 0) {
+ throw new IllegalArgumentException("Arguments 'attributes' length must be even. Actual: " + attributes.length);
+ }
for (int i = 0; i < attributes.length; i += 2) {
result.put(attributes[i], attributes[i + 1]);
}
@@ -186,7 +194,7 @@ public class XMLStringBuffer {
* @param tagName The name of the tag
* @param value The value for this tag
*/
- public void addRequired(String tagName, String value) {
+ public void addRequired(String tagName, @Nullable String value) {
addRequired(tagName, value, (Properties) null);
}
@@ -197,10 +205,10 @@ public class XMLStringBuffer {
* @param value The value for this tag
* @param attributes A Properties file containing the attributes (or null)
*/
- public void addRequired(String tagName, String value, Properties attributes) {
+ public void addRequired(String tagName, @Nullable String value, @Nullable Properties attributes) {
XMLUtils.xmlRequired(m_buffer, m_currentIndent, tagName, value, attributes);
}
- public void addRequired(String tagName, String value, String... attributes) {
+ public void addRequired(String tagName, @Nullable String value, String... attributes) {
addRequired(tagName, value, createProperties(attributes));
}
@@ -211,12 +219,16 @@ public class XMLStringBuffer {
* @param value The value for this tag
* @param attributes A Properties file containing the attributes (or null)
*/
- public void addOptional(String tagName, String value, Properties attributes) {
- XMLUtils.xmlOptional(m_buffer, m_currentIndent, tagName, value, attributes);
+ public void addOptional(String tagName, @Nullable String value, @Nullable Properties attributes) {
+ if (value != null) {
+ XMLUtils.xmlOptional(m_buffer, m_currentIndent, tagName, value, attributes);
+ }
}
- public void addOptional(String tagName, String value, String... attributes) {
- XMLUtils.xmlOptional(m_buffer, m_currentIndent, tagName, value, createProperties(attributes));
+ public void addOptional(String tagName, @Nullable String value, String... attributes) {
+ if (value != null) {
+ XMLUtils.xmlOptional(m_buffer, m_currentIndent, tagName, value, createProperties(attributes));
+ }
}
/**
@@ -225,7 +237,7 @@ public class XMLStringBuffer {
* @param tagName The name of the tag
* @param value The value for this tag
*/
- public void addOptional(String tagName, String value) {
+ public void addOptional(String tagName, @Nullable String value) {
addOptional(tagName, value, (Properties) null);
}
@@ -236,7 +248,7 @@ public class XMLStringBuffer {
* @param value The value for this tag
* @param attributes A Properties file containing the attributes (or null)
*/
- public void addOptional(String tagName, Boolean value, Properties attributes) {
+ public void addOptional(String tagName, @Nullable Boolean value, @Nullable Properties attributes) {
if (null != value) {
XMLUtils.xmlOptional(m_buffer, m_currentIndent, tagName, value.toString(), attributes);
}
@@ -247,9 +259,8 @@ public class XMLStringBuffer {
* added.
* @param tagName The name of the tag
* @param value The value for this tag
- * @param attributes A Properties file containing the attributes (or null)
*/
- public void addOptional(String tagName, Boolean value) {
+ public void addOptional(String tagName, @Nullable Boolean value) {
addOptional(tagName, value, null);
}
@@ -268,7 +279,7 @@ public class XMLStringBuffer {
* @param tagName The name of the tag
* @param attributes A Properties file containing the attributes (or null)
*/
- public void addEmptyElement(String tagName, Properties attributes) {
+ public void addEmptyElement(String tagName, @Nullable Properties attributes) {
m_buffer.append(m_currentIndent).append("<").append(tagName);
XMLUtils.appendAttributes(m_buffer, attributes);
m_buffer.append("/>").append(EOL);
diff --git a/src/main/java/org/testng/reporters/XMLUtils.java b/src/main/java/org/testng/reporters/XMLUtils.java
index 5fd03ef..afe61af 100755
--- a/src/main/java/org/testng/reporters/XMLUtils.java
+++ b/src/main/java/org/testng/reporters/XMLUtils.java
@@ -1,5 +1,7 @@
package org.testng.reporters;
+import org.testng.internal.Nullable;
+
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
import java.util.Map.Entry;
@@ -20,12 +22,23 @@ public final class XMLUtils {
// Hide constructor
}
- static public String xml(String indent, String elementName, String content,
- Properties attributes) {
+ /**
+ * Generate tag.
+ * An opening and closing tag will be generated even if value is null.
+ * @param name name of the tag
+ * @param content content for this tag (or null)
+ * @param attributes tag attributes (or null)
+ */
+ static public String xml(String indent,
+ String name,
+ @Nullable String content,
+ @Nullable Properties attributes) {
IBuffer result = Buffer.create();
- xmlOpen(result, indent, elementName, attributes, true /* no newline */);
- result.append(content);
- xmlClose(result, "", elementName, XMLUtils.extractComment(elementName, attributes));
+ xmlOpen(result, indent, name, attributes, true /* no newline */);
+ if (content != null) {
+ result.append(content);
+ }
+ xmlClose(result, "", name, XMLUtils.extractComment(name, attributes));
return result.toString();
}
@@ -52,14 +65,14 @@ public final class XMLUtils {
}
public static void xmlOptional(IBuffer result, String sp,
- String elementName, String value, Properties attributes) {
+ String elementName, @Nullable String value, Properties attributes) {
if (null != value) {
xmlRequired(result, sp, elementName, value, attributes);
}
}
public static void xmlRequired(IBuffer result, String sp,
- String elementName, String value, Properties attributes) {
+ String elementName, @Nullable String value, @Nullable Properties attributes) {
result.append(xml(sp, elementName, value, attributes));
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/testng.git
More information about the pkg-java-commits
mailing list