pingpingy1 commented on PR #123:
URL: https://github.com/apache/johnzon/pull/123#issuecomment-2002889653
@jungm Thanks for the response. I don't think I was quite thinking right
when I wrote those tests.
The following is the NPE that I intended to address:
```java
public static void main(String args[]) throws Exception {
Mapper mapper = MapperLocatorDelegate.locate();
con_recv0.writeObject((Writer) null, (Object) "string");
}
```
```console
Exception in thread "main" java.lang.NullPointerException: Cannot invoke
"java.io.Writer.write(char[], int, int)" because "this.val$from" is null
at
org.apache.johnzon.mapper.internal.Streams$1.write(Streams.java:45)
at
org.apache.johnzon.core.JsonGeneratorImpl.flushBuffer(JsonGeneratorImpl.java:481)
at
org.apache.johnzon.core.JsonGeneratorImpl.close(JsonGeneratorImpl.java:451)
at org.apache.johnzon.mapper.Mapper.writeObject(Mapper.java:188)
at Test.main(Test.java:17)
```
I know that the explicit `null` here makes the problem obvious, but if it
weren't visible, the NPE is thrown not upon writing but later when flushing the
buffer, which I thought could cause problems in some scenarios.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]