Skip to content

Commit 5a774c4

Browse files
committed
Fix four issues flagged in AI code review
- addValueNode: check writeContext.writeValue() return value and report error when called in Object context without a preceding property name - writePropertyId (integer-key path): call writeContext.writeName() to keep Jackson write-context state in sync when supportIntegerKeys=true - MessagePackSerializedString: fix asQuotedUTF8/appendQuotedUTF8/ writeQuotedUTF8/putQuotedUTF8 to return unquoted UTF-8 bytes; SerializableString "quoted" means escaped-not-surrounded-by-quotes, and MessagePack has no JSON special characters to escape - TimestampExtensionModule: wrap IOException as UncheckedIOException instead of plain RuntimeException to preserve the IO failure type
1 parent 2d308e1 commit 5a774c4

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

msgpack-jackson3/src/main/java/org/msgpack/jackson/dataformat/MessagePackGenerator.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,9 @@ private void addKeyNode(Object key)
470470

471471
private void addValueNode(Object value) throws IOException
472472
{
473-
writeContext.writeValue();
473+
if (!writeContext.writeValue()) {
474+
_reportError("Cannot write value: expecting a property name in Object context");
475+
}
474476
switch (currentState) {
475477
case IN_OBJECT: {
476478
Node node = nodes.get(nodes.size() - 1);
@@ -509,6 +511,9 @@ private void writeByteArrayTextValue(byte[] text, int offset, int len) throws IO
509511
public JsonGenerator writePropertyId(long id) throws JacksonException
510512
{
511513
if (this.supportIntegerKeys) {
514+
if (!writeContext.writeName(String.valueOf(id))) {
515+
_reportError("Cannot write property name, not in Object context");
516+
}
512517
addKeyNode(id);
513518
}
514519
else {

msgpack-jackson3/src/main/java/org/msgpack/jackson/dataformat/MessagePackSerializedString.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ public byte[] asUnquotedUTF8()
6161
@Override
6262
public byte[] asQuotedUTF8()
6363
{
64-
return ("\"" + getValue() + "\"").getBytes(UTF8);
64+
return asUnquotedUTF8();
6565
}
6666

6767
@Override
6868
public int appendQuotedUTF8(byte[] bytes, int i)
6969
{
70-
byte[] utf8 = asQuotedUTF8();
70+
byte[] utf8 = asUnquotedUTF8();
7171
System.arraycopy(utf8, 0, bytes, i, utf8.length);
7272
return utf8.length;
7373
}
@@ -100,7 +100,7 @@ public int appendUnquoted(char[] chars, int i)
100100
public int writeQuotedUTF8(OutputStream outputStream)
101101
{
102102
try {
103-
byte[] utf8 = asQuotedUTF8();
103+
byte[] utf8 = asUnquotedUTF8();
104104
outputStream.write(utf8);
105105
return utf8.length;
106106
}
@@ -125,7 +125,7 @@ public int writeUnquotedUTF8(OutputStream outputStream)
125125
@Override
126126
public int putQuotedUTF8(ByteBuffer byteBuffer)
127127
{
128-
byte[] utf8 = asQuotedUTF8();
128+
byte[] utf8 = asUnquotedUTF8();
129129
byteBuffer.put(utf8);
130130
return utf8.length;
131131
}

msgpack-jackson3/src/main/java/org/msgpack/jackson/dataformat/TimestampExtensionModule.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import java.io.ByteArrayOutputStream;
1616
import java.io.IOException;
17+
import java.io.UncheckedIOException;
1718
import java.time.Instant;
1819

1920
public class TimestampExtensionModule
@@ -50,7 +51,7 @@ public void serialize(Instant value, JsonGenerator gen, SerializationContext pro
5051
}
5152
}
5253
catch (IOException e) {
53-
throw new RuntimeException(e);
54+
throw new UncheckedIOException(e);
5455
}
5556
}
5657
}
@@ -77,7 +78,7 @@ public Instant deserialize(JsonParser p, DeserializationContext ctxt)
7778
}
7879
}
7980
catch (IOException e) {
80-
throw new RuntimeException(e);
81+
throw new UncheckedIOException(e);
8182
}
8283
}
8384
}

0 commit comments

Comments
 (0)