Skip to content

Commit 1f26be8

Browse files
committed
Clean up dead code and add OSGi import exclusions for msgpack-jackson3
- Remove JavaInfo.java: STRING_VALUE_FIELD_IS_CHARS is always false on Java 17+ since String.value is byte[], not char[]; simplify parser and generator accordingly - Remove dead writeCharArrayTextKey method and tempChars field - Add OsgiKeys.importPackage exclusions for android.os and sun.* packages - Add comments on (int) cast overflow risk in currentTokenLocation/currentLocation
1 parent d8c66c1 commit 1f26be8

4 files changed

Lines changed: 7 additions & 90 deletions

File tree

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ lazy val msgpackJackson3 = Project(id = "msgpack-jackson3", base = file("msgpack
180180
description := "Jackson 3.x extension that adds support for MessagePack",
181181
OsgiKeys.bundleSymbolicName := "org.msgpack.msgpack-jackson3",
182182
OsgiKeys.exportPackage := Seq("org.msgpack.jackson", "org.msgpack.jackson.dataformat"),
183+
OsgiKeys.importPackage := Seq("!android.os", "!sun.*"),
183184
Test / fork := true,
184185
javacOptions := Seq("-source", "17", "-target", "17"),
185186
doc / javacOptions := Seq("-source", "17", "-Xdoclint:none"),

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

Lines changed: 0 additions & 41 deletions
This file was deleted.

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

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
import java.util.ArrayList;
4545
import java.util.List;
4646

47-
import static org.msgpack.jackson.dataformat.JavaInfo.STRING_VALUE_FIELD_IS_CHARS;
48-
4947
public class MessagePackGenerator
5048
extends GeneratorBase
5149
{
@@ -513,16 +511,6 @@ private boolean areAllAsciiBytes(byte[] bytes, int offset, int len)
513511
return true;
514512
}
515513

516-
private void writeCharArrayTextKey(char[] text, int offset, int len)
517-
{
518-
byte[] bytes = getBytesIfAscii(text, offset, len);
519-
if (bytes != null) {
520-
addKeyNode(new AsciiCharString(bytes));
521-
return;
522-
}
523-
addKeyNode(new String(text, offset, len));
524-
}
525-
526514
private void writeCharArrayTextValue(char[] text, int offset, int len) throws IOException
527515
{
528516
byte[] bytes = getBytesIfAscii(text, offset, len);
@@ -563,13 +551,7 @@ public JacksonFeatureSet<StreamWriteCapability> streamWriteCapabilities()
563551
@Override
564552
public JsonGenerator writeName(String name) throws JacksonException
565553
{
566-
if (STRING_VALUE_FIELD_IS_CHARS.get()) {
567-
char[] chars = name.toCharArray();
568-
writeCharArrayTextKey(chars, 0, chars.length);
569-
}
570-
else {
571-
addKeyNode(name);
572-
}
554+
addKeyNode(name);
573555
return this;
574556
}
575557

@@ -592,13 +574,7 @@ else if (name instanceof MessagePackSerializedString) {
592574
public JsonGenerator writeString(String text) throws JacksonException
593575
{
594576
try {
595-
if (STRING_VALUE_FIELD_IS_CHARS.get()) {
596-
char[] chars = text.toCharArray();
597-
writeCharArrayTextValue(chars, 0, chars.length);
598-
}
599-
else {
600-
addValueNode(text);
601-
}
577+
addValueNode(text);
602578
}
603579
catch (IOException e) {
604580
throw _wrapIOFailure(e);
@@ -673,13 +649,7 @@ public JsonGenerator writeUTF8String(byte[] text, int offset, int length) throws
673649
public JsonGenerator writeRaw(String text) throws JacksonException
674650
{
675651
try {
676-
if (STRING_VALUE_FIELD_IS_CHARS.get()) {
677-
char[] chars = text.toCharArray();
678-
writeCharArrayTextValue(chars, 0, chars.length);
679-
}
680-
else {
681-
addValueNode(text);
682-
}
652+
addValueNode(text);
683653
}
684654
catch (IOException e) {
685655
throw _wrapIOFailure(e);

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

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
import java.math.BigInteger;
4343
import java.nio.charset.StandardCharsets;
4444

45-
import static org.msgpack.jackson.dataformat.JavaInfo.STRING_VALUE_FIELD_IS_CHARS;
46-
4745
public class MessagePackParser
4846
extends ParserMinimalBase
4947
{
@@ -61,7 +59,6 @@ public class MessagePackParser
6159
private final IOContext ioContext;
6260
private ExtensionTypeCustomDeserializers extTypeCustomDesers;
6361
private final byte[] tempBytes = new byte[64];
64-
private final char[] tempChars = new char[64];
6562

6663
private enum Type
6764
{
@@ -146,19 +143,7 @@ private String unpackString(MessageUnpacker messageUnpacker) throws IOException
146143
int strLen = messageUnpacker.unpackRawStringHeader();
147144
if (strLen <= tempBytes.length) {
148145
messageUnpacker.readPayload(tempBytes, 0, strLen);
149-
if (STRING_VALUE_FIELD_IS_CHARS.get()) {
150-
for (int i = 0; i < strLen; i++) {
151-
byte b = tempBytes[i];
152-
if ((0x80 & b) != 0) {
153-
return new String(tempBytes, 0, strLen, StandardCharsets.UTF_8);
154-
}
155-
tempChars[i] = (char) b;
156-
}
157-
return new String(tempChars, 0, strLen);
158-
}
159-
else {
160-
return new String(tempBytes, 0, strLen);
161-
}
146+
return new String(tempBytes, 0, strLen);
162147
}
163148
else {
164149
byte[] bytes = messageUnpacker.readPayload(strLen);
@@ -604,12 +589,14 @@ public TokenStreamContext streamReadContext()
604589
@Override
605590
public TokenStreamLocation currentTokenLocation()
606591
{
592+
// columnNr repurposed as byte offset; truncates for inputs > 2 GB
607593
return new TokenStreamLocation(ioContext.contentReference(), tokenPosition, -1, (int) tokenPosition);
608594
}
609595

610596
@Override
611597
public TokenStreamLocation currentLocation()
612598
{
599+
// columnNr repurposed as byte offset; truncates for inputs > 2 GB
613600
return new TokenStreamLocation(ioContext.contentReference(), currentPosition, -1, (int) currentPosition);
614601
}
615602

0 commit comments

Comments
 (0)