[Hard] HugeGryoModule.java: ` — `VertexLabelKryoSerializer.read()` returns null, unimple
Source
- File:
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/io/HugeGryoModule.java - References: L151-L152
Now I have a clear picture of the issue. Let me summarize what I found:
-
In
HugeGryoModule.java, there are four Kryo serializer classes for schema types:PropertyKeyKryoSerializerVertexLabelKryoSerializerEdgeLabelKryoSerializerIndexLabelKryoSerializer
-
Each of these has a
write()method that is fully implemented (usingGraphSONSchemaSerializerto convert the schema object to aMap<HugeKeys, Object>, then writing it viawriteEntry()). -
However, each
read()method is a stub that just returnsnullwith a// TODOcomment. -
There's also a
readEntry()helper method that exists but is marked@SuppressWarnings("unused")— it's never called because theread()methods are all stubs.
The issue is that:
- The Gryo (Kryo-based binary) serialization format is used for TinkerPop's Gryo I/O (binary graph format)
- When deserializing schema objects from Gryo format (e.g., reading a graph exported in Gryo format), all four schema type deserializers return
nullinstead of reconstructing the actual objects - This means any code path that reads schema objects from Gryo binary format will silently get
nullback, which could cause NullPointerExceptions or incorrect behavior
The fix would require:
- Implementing
readEntry()usage in eachread()method - But there's a complication:
GraphSONSchemaSerializer.writeVertexLabel()serializes property key names (strings) rather than IDs, and theread()methods would need aHugeGraphreference to look up those names back to IDs — which the KryoSerializer.read()signature doesn't provide directly.
This is the same challenge that HugeGraphSONModule faces — it only registers serializers (not deserializers) for schema types.
The readEntry() helper is already there and marked @SuppressWarnings("unused"). The issue is that to reconstruct a VertexLabel from the map, you need a HugeGraph reference (to resolve property key names to IDs), which isn't available in the Kryo serializer context.
Files affected: Only 1 file directly contains the TODO stubs — HugeGryoModule.java. But implementing the fix properly might require changes to GraphSONSchemaSerializer to add read methods, or adding a way to pass the graph context to the serializer.
Let me count the files that would need to change:
HugeGryoModule.java- the fourread()methods need implementation- Possibly
GraphSONSchemaSerializer.java- would needreadVertexLabel,readEdgeLabel,readPropertyKey,readIndexLabelmethods (currently it only has write methods)
Actually, looking at the existing code more carefully:
VertexLabel.fromMap()exists and can reconstruct from a mapreadEntry()already exists inHugeGryoModule.javato read the map back
The problem is that GraphSONSchemaSerializer.writeVertexLabel() stores property key names (strings), not IDs. So to reconstruct, you'd need a graph reference to look up IDs from names. The Kryo serializer doesn't have access to the graph.
So the fix would need either:
- Store IDs instead of names in the write path (breaking change to serialization format)
- Pass the graph reference to the serializer somehow (e.g., via constructor)
- Use a different approach
Actually, looking at VertexLabel.fromMap(), it works with IDs (integers), not names. So the GraphSONSchemaSerializer.writeVertexLabel() format (which uses names) is incompatible with VertexLabel.fromMap().
The files affected would be:
HugeGryoModule.java- primary file with the TODOs (4 read methods)- Possibly
GraphSONSchemaSerializer.java- if read methods need to be added there
That's essentially 1-2 files directly, though the design challenge (needing a graph reference) is the real blocker.
The Issue
The problem is a complete asymmetry between serialization and deserialization in the Gryo (Kryo-based binary) schema serializers. All four schema-type Kryo serializers in HugeGryoModule.java have fully implemented write() methods but stub read() methods that unconditionally return null.
The four broken read() stubs
All four inner classes share the same pattern:
// PropertyKeyKryoSerializer (line 151-154)
@Override
public PropertyKey read(Kryo kryo, Input input, Class<PropertyKey> c) {
// TODO
return null;
}
// VertexLabelKryoSerializer (line 165-168)
@Override
public VertexLabel read(Kryo kryo, Input input, Class<VertexLabel> c) {
// TODO
return null;
}
// EdgeLabelKryoSerializer (line 179-182)
@Override
public EdgeLabel read(Kryo kryo, Input input, Class<EdgeLabel> clazz) {
// TODO
return null;
}
// IndexLabelKryoSerializer (line 193-196)
@Override
public IndexLabel read(Kryo kryo, Input input, Class<IndexLabel> c) {
// TODO
return null;
}
What the write() side does
Each write() method calls GraphSONSchemaSerializer to produce a Map<HugeKeys, Object> (with string names for property keys, not IDs), then serializes it via writeEntry():
public void write(Kryo kryo, Output output, VertexLabel vl) {
writeEntry(kryo, output, schemaSerializer.writeVertexLabel(vl));
}
There is even a readEntry() helper already written (but marked @SuppressWarnings("unused") because nothing calls it):
@SuppressWarnings("unused")
private static Map<HugeKeys, Object> readEntry(Kryo kryo, Input input) { ... }
The deeper design problem
The read() methods can't simply call readEntry() and reconstruct the object, because:
-
GraphSONSchemaSerializer.writeVertexLabel()stores property key names (strings), not numeric IDs. -
Reconstructing a
VertexLabelfrom names requires aHugeGraphreference to resolve names back toIdobjects — but the KryoSerializer.read()signature only providesKryo,Input, and the targetClass. There is no graph context available. -
GraphSONSchemaSerializerhas noread*methods at all — it is write-only.
Note: HugeGraphSONModule (the JSON counterpart) has the same gap — it only registers serializers, not deserializers, for schema types.
What needs to change
To fix this properly, 2 files would be directly affected:
| File | Change needed |
|---|---|
HugeGryoModule.java |
Implement all 4 read() methods; pass a HugeGraph reference via constructor to each serializer class |
GraphSONSchemaSerializer.java |
Add readVertexLabel, readEdgeLabel, readPropertyKey, readIndexLabel methods that accept a Map<HugeKeys, Object> and a HugeGraph and reconstruct the schema objects |
The HugeGraphIoRegistry or register() call site may also need a minor touch to supply the graph reference to the serializer constructors, but the core logic is confined to those 2 files.
This was created accidentally during testing closing. Sorry for the noise.