#1321 CPD format XML fails with NullPointer

This commit is contained in:
Andreas Dangel
2015-03-15 19:39:09 +01:00
parent 65398d9eed
commit 28dfbeabf8
3 changed files with 19 additions and 5 deletions

View File

@ -32,15 +32,19 @@ public final class XMLRenderer implements Renderer {
* Creates a XML Renderer with the default (platform dependent) encoding.
*/
public XMLRenderer() {
this(System.getProperty("file.encoding"));
this(null);
}
/**
* Creates a XML Renderer with a specific output encoding.
* @param encoding the encoding to use
* @param encoding the encoding to use or null. If null, default (platform dependent) encoding is used.
*/
public XMLRenderer(String encoding) {
this.encoding = encoding;
if (encoding != null) {
this.encoding = encoding;
} else {
this.encoding = System.getProperty("file.encoding");
}
}
private Document createDocument() {

View File

@ -9,9 +9,8 @@ import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.util.regex.Pattern;
import junit.framework.Assert;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@ -105,6 +104,16 @@ public class CPDCommandLineInterfaceTest {
Assert.assertTrue(out.contains("Found a 5 line (13 tokens) duplication"));
}
@Test
public void testFormatXmlWithoutEncoding() throws Exception {
runCPD("--minimum-tokens", "10",
"--language", "java",
"--files", "src/test/resources/net/sourceforge/pmd/cpd/clitest/",
"--format", "xml");
String out = bufferStdout.toString("UTF-8");
Assert.assertTrue(out.contains("<duplication lines=\"3\" tokens=\"10\">"));
}
private void runCPD(String... args) {
System.setProperty(CPDCommandLineInterface.NO_EXIT_AFTER_RUN, "true");
CPD.main(args);

View File

@ -81,6 +81,7 @@ and will be removed with the next release of PMD.
* [#1316](https://sourceforge.net/p/pmd/bugs/1316/): Multi Rule Properties with delimiter not possible
* [#1317](https://sourceforge.net/p/pmd/bugs/1317/): RuntimeException when parsing class with multiple lambdas
* [#1319](https://sourceforge.net/p/pmd/bugs/1319/): PMD stops with NoClassDefFoundError (typeresolution)
* [#1321](https://sourceforge.net/p/pmd/bugs/1321/): CPD format XML fails with NullPointer
**API Changes:**