-
Notifications
You must be signed in to change notification settings - Fork 4.5k
[BEAM-171] Fix JAXBCoder in the nested context #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
JAXBCoder in the nested context is broken with any coder that writes content after the output of the XML stream, as decode will read the entire remaining stream and fail. In the nested context, prepend a long representing the size of the XML while encoding, and limit the size of the returned stream while decoding.
|
R: @dhalperi |
| } | ||
| if (context.equals(Context.NESTED)) { | ||
| CountingOutputStream countingStream = | ||
| new CountingOutputStream( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| @Override | ||
| public void close() { | ||
| // Do nothing. JAXB closes the underyling stream so we must filter out those calls. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove newline.
Also, I was wrong about flush -- no need to flush an input stream (duh)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| jaxbUnmarshaller.unmarshal( | ||
| new CloseIgnoringInputStream(ByteStreams.limit(inStream, limit))); | ||
| return obj; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about extracting the common core for simplicity?
InputStream stream = inStream;
if (!context.isWholeStream) {
long limit = VarInt.decodeLong();
stream = ByteStreams.limit(stream, limit);
}
@SuppressWarnings("unchecked")
T obj = (T) jaxbUnmarshaller.unmarshal(new CloseIgnoringInputStream(stream));
return obj;There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
beam issue? |
|
|
||
| @Override | ||
| public void close() { | ||
| // Do nothing. JAXB closes the underyling stream so we must filter out those calls. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: underlying
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| new FilterOutputStream(outStream) { | ||
| // JAXB closes the underlying stream so we must filter out those calls. | ||
| @Override | ||
| public void close() throws IOException {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one needs the flush, I think. It's an output stream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one should be backported.
Also, why separate out CloseIgnoringInputStream but not CloseIgnoringOutputStream?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An artifact of the implementation.
|
Stopped flushing, as discussed, as the marshaller must have already written its contents to the stream before closed, and the stream will be flushed and closed by the actual owner. |
|
LGTM, merging |
#! Prevent deleting wrong timers
* chore: update minimum version of protoplus to ensure DatetimeWithNanoseconds availability * feat: Incorporate nanoseconds back into components, such as hashing * blacken * remove unused imports
Be sure to do all of the following to help us incorporate your contribution
quickly and easily:
[BEAM-<Jira issue #>] Description of pull requestmvn clean verify. (Even better, enableTravis-CI on your fork and ensure the whole test matrix passes).
number, if there is one.
Individual Contributor License Agreement.
JAXBCoder in the nested context is broken with any coder that writes
content after the output of the XML stream, as decode will read the
entire remaining stream and fail.
In the nested context, prepend a long representing the size of the XML
while encoding, and limit the size of the returned stream while
decoding.
Replaces #112
This should not be ported to the DataflowJavaSDK