Skip to content

Commit 4847848

Browse files
committed
Try to fix that one pesky little test failure for protobuf module
1 parent a465114 commit 4847848

File tree

6 files changed

+36
-20
lines changed

6 files changed

+36
-20
lines changed

protobuf/src/main/java/module-info.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
requires tools.jackson.core;
55
requires tools.jackson.databind;
66

7+
// No module-info nor Automatic-Module-Name; relies on jar name:
78
requires protoparser;
89

910
exports tools.jackson.dataformat.protobuf;
10-
// No, should not expose shaded
11-
// exports tools.jackson.dataformat.protobuf.protoparser.protoparser;
1211
exports tools.jackson.dataformat.protobuf.schema;
1312
exports tools.jackson.dataformat.protobuf.schemagen;
1413

14+
// Need to "opens" to allow reading resource `descriptor.proto`
15+
opens tools.jackson.dataformat.protobuf.schema;
16+
1517
provides tools.jackson.core.TokenStreamFactory with
1618
tools.jackson.dataformat.protobuf.ProtobufFactory;
1719
provides tools.jackson.databind.ObjectMapper with

protobuf/src/main/java/tools/jackson/dataformat/protobuf/schema/DescriptorLoader.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
*/
1616
public class DescriptorLoader
1717
{
18-
protected final static String DESCRIPTOR_PROTO = "/descriptor.proto";
18+
protected final static String DESCRIPTOR_PROTO = "/tools/jackson/dataformat/protobuf/schema/descriptor.proto";
19+
//protected final static String DESCRIPTOR_PROTO = "descriptor.proto";
1920

2021
/**
2122
* Fully configured reader for {@link FileDescriptorSet} objects.
@@ -38,13 +39,20 @@ public static DescriptorLoader construct(ProtobufMapper mapper) throws IOExcepti
3839
}
3940

4041
/**
41-
* @param mapper {@link ObjectMapper} that can reader protoc content.
42+
* @param mapper {@link ObjectMapper} that can read protoc content.
4243
*/
4344
public static DescriptorLoader construct(ObjectMapper mapper,
4445
ProtobufSchemaLoader schemaLoader) throws IOException
4546
{
4647
ProtobufSchema schema;
47-
try (InputStream in = DescriptorLoader.class.getResourceAsStream(DESCRIPTOR_PROTO)) {
48+
final Class<?> ctxt = DescriptorLoader.class;
49+
final String resourceName = DESCRIPTOR_PROTO;
50+
try (InputStream in = ctxt.getResourceAsStream(resourceName)) {
51+
if (in == null) {
52+
throw new IllegalStateException(String.format(
53+
"Can not find resource `%s` within context '%s'",
54+
resourceName, ctxt.getName()));
55+
}
4856
schema = schemaLoader.load(in, "FileDescriptorSet");
4957
}
5058
return new DescriptorLoader(mapper.readerFor(FileDescriptorSet.class)

protobuf/src/main/java/tools/jackson/dataformat/protobuf/schema/ProtobufSchemaLoader.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.*;
44
import java.net.URL;
55
import java.nio.charset.Charset;
6+
import java.util.Objects;
67

78
import com.squareup.protoparser.ProtoFile;
89
import com.squareup.protoparser.ProtoParser;
@@ -40,27 +41,27 @@ public ProtobufSchemaLoader() { }
4041
*/
4142

4243
public ProtobufSchema load(URL url) throws IOException {
43-
return loadNative(url).forFirstType();
44+
return loadNative(Objects.requireNonNull(url)).forFirstType();
4445
}
4546

4647
/**
4748
* @param rootTypeName Name of message type in schema definition that is
4849
* the root value to read/write
4950
*/
5051
public ProtobufSchema load(URL url, String rootTypeName) throws IOException {
51-
return loadNative(url).forType(rootTypeName);
52+
return loadNative(Objects.requireNonNull(url)).forType(rootTypeName);
5253
}
5354

5455
public ProtobufSchema load(File f) throws IOException {
55-
return loadNative(f).forFirstType();
56+
return loadNative(Objects.requireNonNull(f)).forFirstType();
5657
}
5758

5859
/**
5960
* @param rootTypeName Name of message type in schema definition that is
6061
* the root value to read/write
6162
*/
6263
public ProtobufSchema load(File f, String rootTypeName) throws IOException {
63-
return loadNative(f).forType(rootTypeName);
64+
return loadNative(Objects.requireNonNull(f)).forType(rootTypeName);
6465
}
6566

6667
/**
@@ -69,15 +70,15 @@ public ProtobufSchema load(File f, String rootTypeName) throws IOException {
6970
* Note that given {@link InputStream} will be closed before method returns.
7071
*/
7172
public ProtobufSchema load(InputStream in) throws IOException {
72-
return loadNative(in, true).forFirstType();
73+
return loadNative(Objects.requireNonNull(in), true).forFirstType();
7374
}
7475

7576
/**
7677
* @param rootTypeName Name of message type in schema definition that is
7778
* the root value to read/write
7879
*/
7980
public ProtobufSchema load(InputStream in, String rootTypeName) throws IOException {
80-
return loadNative(in, true).forType(rootTypeName);
81+
return loadNative(Objects.requireNonNull(in), true).forType(rootTypeName);
8182
}
8283

8384
/**
@@ -86,15 +87,15 @@ public ProtobufSchema load(InputStream in, String rootTypeName) throws IOExcepti
8687
* Note that given {@link Reader} will be closed before method returns.
8788
*/
8889
public ProtobufSchema load(Reader r) throws IOException {
89-
return loadNative(r, true).forFirstType();
90+
return loadNative(Objects.requireNonNull(r), true).forFirstType();
9091
}
9192

9293
/**
9394
* @param rootTypeName Name of message type in schema definition that is
9495
* the root value to read/write
9596
*/
9697
public ProtobufSchema load(Reader r, String rootTypeName) throws IOException {
97-
return loadNative(r, true).forType(rootTypeName);
98+
return loadNative(Objects.requireNonNull(r), true).forType(rootTypeName);
9899
}
99100

100101
/**
@@ -120,22 +121,27 @@ public ProtobufSchema parse(String schemaAsString, String rootTypeName) throws I
120121
*/
121122

122123
public NativeProtobufSchema loadNative(File f) throws IOException {
124+
Objects.requireNonNull(f);
123125
return NativeProtobufSchema.construct(_loadNative(f));
124126
}
125127

126128
public NativeProtobufSchema loadNative(URL url) throws IOException {
129+
Objects.requireNonNull(url);
127130
return NativeProtobufSchema.construct(_loadNative(url));
128131
}
129132

130133
public NativeProtobufSchema parseNative(String schema) throws IOException {
134+
Objects.requireNonNull(schema);
131135
return NativeProtobufSchema.construct(_loadNative(schema));
132136
}
133137

134138
public NativeProtobufSchema loadNative(InputStream in, boolean close) throws IOException {
139+
Objects.requireNonNull(in);
135140
return NativeProtobufSchema.construct(_loadNative(in, close));
136141
}
137142

138143
protected NativeProtobufSchema loadNative(Reader r, boolean close) throws IOException {
144+
Objects.requireNonNull(r);
139145
return NativeProtobufSchema.construct(_loadNative(r, close));
140146
}
141147

protobuf/src/test/java/tools/jackson/dataformat/protobuf/ProtobufTestBase.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public String toString() {
318318

319319
// // // POJOs for "JVM-serializers" case
320320

321-
protected static class MediaItem
321+
public static class MediaItem
322322
{
323323
public Media media;
324324
public List<Image> images;
@@ -375,9 +375,9 @@ public boolean equals(Object o) {
375375
}
376376
}
377377

378-
enum Size { SMALL, LARGE };
378+
public enum Size { SMALL, LARGE };
379379

380-
static class Image
380+
public static class Image
381381
{
382382
public Image() { }
383383
public Image(String uri, String title, int w, int h, Size s) {
@@ -410,9 +410,9 @@ && _equals(size, other.size)
410410
}
411411
}
412412

413-
enum Player { JAVA, FLASH; }
413+
public enum Player { JAVA, FLASH; }
414414

415-
static class Media {
415+
public static class Media {
416416

417417
public String uri;
418418
public String title; // Can be unset.

protobuf/src/test/java/tools/jackson/dataformat/protobuf/dos/DeepNestingProtobufParserTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
*/
2121
public class DeepNestingProtobufParserTest extends ProtobufTestBase
2222
{
23-
static class Node {
23+
public static class Node {
2424
public int id;
2525
public Node next;
2626

27-
protected Node() { }
27+
public Node() { }
2828
public Node(int id, Node next) {
2929
this.id = id;
3030
this.next = next;

0 commit comments

Comments
 (0)