Support reading TG files with shared and non-shared value contexts
This is part of the fix for a nasty corner case in
TransferableGraphFileReader.readTG's deserialization of referable value
data types.
This regression was caused by commit
bf495713dbc9dec325f3929889466fa6cd58b541 over 1.5 years ago. The removal
of idContext.clear() was done without proper understanding of the real
issue.
The real issue is that TG's are currently written in two ways by
different codes: with shared and with non-shared value contexts.
Serializing TransferableGraph1 structures using the default Binding will
use shared context for serializing the values Variant array. Thus all TG
files produced by the graph compiler use a shared value context which
eans this class must be used with sharedValueContext set to true. As an
example, <code>true</code> must be used if the corresponding TG file is
written e.g. like this:
DataContainers.writeFile(location
new DataContainer(format,
version,
metadata,
new Variant(TransferableGraph1.BINDING, tg)));
On the other hand, any TG files serialized using more optimized methods
like ModelTransferableGraphSource do not use a shared value context when
writing the file. This means those files cannot be read safely using
standard {@link Binding} at all, and when using this class,
sharedValueContext must be set to false to prevent the import from
corrupting datatype values because the referable parts of datatypes may
get bound to the wrong existing types if the data is read using shared
context.
After this change clients should use readTG(File | InputStream, boolean)
methods instead of readTG to always specify the context sharing setting
explicitly according to how the TG's in question were written.
gitlab #409
Change-Id: Ic18fd1442987d4e740f729729b81cd3133f5d269
(cherry picked from commit
c4431acdac59b8aa8a29f87203a3ae90f9475c97)