Skip to content

Commit 213daba

Browse files
authored
Do not allow mixing UTC and legacy datetime and throw ProtocolException on unknown struct types (neo4j#1260)
1 parent a2d3da8 commit 213daba

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

driver/src/main/java/org/neo4j/driver/internal/messaging/common/CommonValueUnpacker.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.util.Map;
4040
import org.neo4j.driver.Value;
4141
import org.neo4j.driver.exceptions.ClientException;
42+
import org.neo4j.driver.exceptions.ProtocolException;
4243
import org.neo4j.driver.internal.InternalNode;
4344
import org.neo4j.driver.internal.InternalPath;
4445
import org.neo4j.driver.internal.InternalRelationship;
@@ -189,21 +190,29 @@ private Value unpackStruct(long size, byte type) throws IOException {
189190
if (!dateTimeUtcEnabled) {
190191
ensureCorrectStructSize(TypeConstructor.DATE_TIME, DATE_TIME_STRUCT_SIZE, size);
191192
return unpackDateTimeWithZoneOffset();
193+
} else {
194+
throw instantiateExceptionForUnknownType(type);
192195
}
193196
case DATE_TIME_WITH_ZONE_OFFSET_UTC:
194197
if (dateTimeUtcEnabled) {
195198
ensureCorrectStructSize(TypeConstructor.DATE_TIME, DATE_TIME_STRUCT_SIZE, size);
196199
return unpackDateTimeUtcWithZoneOffset();
200+
} else {
201+
throw instantiateExceptionForUnknownType(type);
197202
}
198203
case DATE_TIME_WITH_ZONE_ID:
199204
if (!dateTimeUtcEnabled) {
200205
ensureCorrectStructSize(TypeConstructor.DATE_TIME, DATE_TIME_STRUCT_SIZE, size);
201206
return unpackDateTimeWithZoneId();
207+
} else {
208+
throw instantiateExceptionForUnknownType(type);
202209
}
203210
case DATE_TIME_WITH_ZONE_ID_UTC:
204211
if (dateTimeUtcEnabled) {
205212
ensureCorrectStructSize(TypeConstructor.DATE_TIME, DATE_TIME_STRUCT_SIZE, size);
206213
return unpackDateTimeUtcWithZoneId();
214+
} else {
215+
throw instantiateExceptionForUnknownType(type);
207216
}
208217
case DURATION:
209218
ensureCorrectStructSize(TypeConstructor.DURATION, DURATION_TIME_STRUCT_SIZE, size);
@@ -225,7 +234,7 @@ private Value unpackStruct(long size, byte type) throws IOException {
225234
ensureCorrectStructSize(TypeConstructor.PATH, 3, size);
226235
return unpackPath();
227236
default:
228-
throw new IOException("Unknown struct type: " + type);
237+
throw instantiateExceptionForUnknownType(type);
229238
}
230239
}
231240

@@ -430,6 +439,10 @@ private ZonedDateTime newZonedDateTimeUsingUtcBaseline(long epochSecondLocal, in
430439
return ZonedDateTime.of(localDateTime, zoneId);
431440
}
432441

442+
private ProtocolException instantiateExceptionForUnknownType(byte type) {
443+
return new ProtocolException("Unknown struct type: " + type);
444+
}
445+
433446
protected int getNodeFields() {
434447
return NODE_FIELDS;
435448
}

0 commit comments

Comments
 (0)