Skip to content

Commit

Permalink
Use a ArrayDeque and enable test only for JDK < 1.8 (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed May 10, 2023
1 parent 02e2c78 commit 8351c4e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Expand Up @@ -18,6 +18,8 @@

import java.io.PrintWriter;
import java.io.Writer;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.LinkedList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -35,7 +37,7 @@ public class PrettyPrintXMLWriter

private PrintWriter writer;

private LinkedList<String> elementStack = new LinkedList<String>();
private final Deque<String> elementStack = new ArrayDeque<>();

private boolean tagInProgress;

Expand Down Expand Up @@ -307,11 +309,6 @@ public void endElement()
{
finishTag();

// see issue #51: https://github.com/codehaus-plexus/plexus-utils/issues/51
// Rationale: replaced 1 write() with string concatenations with 3 write()
// (this avoids the string concatenation optimization bug detected in Java 7)
// TODO: change the below code to a more efficient expression when the library
// be ready to target Java 8.
write( "</" );
write( elementStack.removeLast() );
write( ">" );
Expand Down Expand Up @@ -518,7 +515,7 @@ protected String getDocType()
/**
* @return the current elementStack;
*/
protected LinkedList<String> getElementStack()
protected Deque<String> getElementStack()
{
return elementStack;
}
Expand Down
Expand Up @@ -18,8 +18,9 @@

import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.NoSuchElementException;

Expand All @@ -28,6 +29,7 @@
import org.codehaus.plexus.util.StringUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -178,6 +180,7 @@ public void testendElementAlreadyClosed()
*
* @throws java.io.IOException if an I/O error occurs
*/
@Disabled( "This test is only relevant on JDK 1.7, which is not supported anymore" )
@Test
public void testIssue51DetectJava7ConcatenationBug()
throws IOException
Expand All @@ -191,7 +194,7 @@ public void testIssue51DetectJava7ConcatenationBug()

int iterations = 20000;

try ( OutputStreamWriter osw = new OutputStreamWriter( Files.newOutputStream( xmlFile.toPath() ), "UTF-8" ) )
try ( Writer osw = Files.newBufferedWriter( xmlFile.toPath(), StandardCharsets.UTF_8 ) )
{
writer = new PrettyPrintXMLWriter( osw );
for ( int i = 0; i < iterations; ++i )
Expand Down

0 comments on commit 8351c4e

Please sign in to comment.