Skip to content
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

IonValue.writeTo(IonHashWriter) fails for IonStruct #20

Open
mcliedtke opened this issue Jun 25, 2019 · 3 comments
Open

IonValue.writeTo(IonHashWriter) fails for IonStruct #20

mcliedtke opened this issue Jun 25, 2019 · 3 comments
Labels

Comments

@mcliedtke
Copy link

Hello,
Just was experimenting with the IonHashWriter and encountered an error when writing an IonStruct DOM object.

IonSystem ion = IonSystemBuilder.standard().build();
IonHasherProvider hasherProvider = new MessageDigestIonHasherProvider("SHA-256");

// write a simple Ion struct and compute the hash
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IonWriter writer = ion.newTextWriter(baos);
IonHashWriter hashWriter = IonHashWriterBuilder.standard()
        .withHasherProvider(hasherProvider)
	.withWriter(writer)
	.build();
		
IonValue ionValue = ion.singleValue("{first_name:\"Amanda\",middle_name:\"Amanda\",last_name:\"Smith\"}");

System.out.println("writer");
ionValue.writeTo(hashWriter);

Stack trace (fails here)

com.amazon.ionhash.IonHashWriterImpl cannot be cast to com.amazon.ion.impl._Private_IonWriter
	at com.amazon.ion.impl.lite.IonValueLite.writeTo(IonValueLite.java:993)
	at com.amazon.ion.impl.lite.IonValueLite.writeChildren(IonValueLite.java:986)
	at com.amazon.ion.impl.lite.IonStructLite.writeBodyTo(IonStructLite.java:809)
	at com.amazon.ion.impl.lite.IonValueLite.writeTo(IonValueLite.java:1010)
	at com.amazon.ion.impl.lite.IonValueLite.writeTo(IonValueLite.java:965)
	at com.amazon.ionhash.IonHashWriterImpl.writeValue(IonHashWriterImpl.java:324)

This seems to only fail on Structs but I haven't tried too many other values. Is the IonHashWriter intended to support writes like this?

@pbcornell
Copy link

This is a bug, although perhaps not too surprising as the focus has been solely on non-DOM usage. Wrapping the IonReader returned by IonSystem.newReader(IonValue) with an IonHashReader allows a hash to be computed from a DOM, but clearly doesn't address the "serialize an IonValue and compute its hash" use case suggested by the code above.

@pbcornell
Copy link

We could address this with changes to ion-hash-java; alternatively, fixing amazon-ion/ion-java#11 would enable other use cases as well (e.g., a schema-validating reader/writer).

@othonrsanchez
Copy link

any update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants