Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Commit 8d126b5

Browse files
committed
Fix UTF8Writer problem, similar to #70
1 parent f503807 commit 8d126b5

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/main/java/com/fasterxml/jackson/dataformat/yaml/UTF8Writer.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public UTF8Writer(OutputStream out)
4444
byte[] buffer = _bufferHolder[0];
4545
if (buffer == null) {
4646
_bufferHolder[0] = buffer = new byte[DEFAULT_BUFFER_SIZE];
47+
} else {
48+
_bufferHolder[0] = null;
4749
}
4850
_outBuffer = buffer;
4951
/* Max. expansion for a single char (in unmodified UTF-8) is
@@ -69,16 +71,14 @@ private static byte[][] _findBufferHolder()
6971
}
7072

7173
@Override
72-
public Writer append(char c)
73-
throws IOException
74+
public Writer append(char c) throws IOException
7475
{
7576
write(c);
7677
return this;
7778
}
7879

7980
@Override
80-
public void close()
81-
throws IOException
81+
public void close() throws IOException
8282
{
8383
if (_out != null) {
8484
if (_outPtr > 0) {
@@ -88,10 +88,12 @@ public void close()
8888
OutputStream out = _out;
8989
_out = null;
9090

91-
byte[] buf = _outBuffer;
92-
if (buf != null) {
93-
_outBuffer = null;
94-
_bufferHolder[0] = buf;
91+
if (_bufferHolder != null) {
92+
byte[] buf = _outBuffer;
93+
if (buf != null) {
94+
_outBuffer = null;
95+
_bufferHolder[0] = buf;
96+
}
9597
}
9698
out.close();
9799

@@ -107,8 +109,7 @@ public void close()
107109
}
108110

109111
@Override
110-
public void flush()
111-
throws IOException
112+
public void flush() throws IOException
112113
{
113114
if (_out != null) {
114115
if (_outPtr > 0) {
@@ -120,15 +121,13 @@ public void flush()
120121
}
121122

122123
@Override
123-
public void write(char[] cbuf)
124-
throws IOException
124+
public void write(char[] cbuf) throws IOException
125125
{
126126
write(cbuf, 0, cbuf.length);
127127
}
128128

129129
@Override
130-
public void write(char[] cbuf, int off, int len)
131-
throws IOException
130+
public void write(char[] cbuf, int off, int len) throws IOException
132131
{
133132
if (len < 2) {
134133
if (len == 1) {
@@ -276,7 +275,7 @@ public void write(String str) throws IOException
276275
}
277276

278277
@Override
279-
public void write(String str, int off, int len) throws IOException
278+
public void write(String str, int off, int len) throws IOException
280279
{
281280
if (len < 2) {
282281
if (len == 1) {

src/test/java/com/fasterxml/jackson/dataformat/yaml/ExceptionConversionTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public void testSimpleParsingLeakage() throws Exception
1919
} catch (org.yaml.snakeyaml.scanner.ScannerException e) {
2020
fail("Internal exception type: "+e);
2121
} catch (JsonMappingException e) {
22-
e.printStackTrace();
22+
// e.printStackTrace();
23+
verifyException(e, "YAML decoding problem");
2324
// good
2425
} catch (Exception e) {
2526
fail("Unknown exception: "+e);

0 commit comments

Comments
 (0)