Skip to content

Commit 3f3c982

Browse files
authored
Do not allow mixing UTC and legacy datetime and throw ProtocolException on unknown struct types (#1260) (#1263)
1 parent 125bb14 commit 3f3c982

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;
@@ -188,21 +189,29 @@ protected Value unpackStruct(long size, byte type) throws IOException {
188189
if (!dateTimeUtcEnabled) {
189190
ensureCorrectStructSize(TypeConstructor.DATE_TIME, DATE_TIME_STRUCT_SIZE, size);
190191
return unpackDateTimeWithZoneOffset();
192+
} else {
193+
throw instantiateExceptionForUnknownType(type);
191194
}
192195
case DATE_TIME_WITH_ZONE_OFFSET_UTC:
193196
if (dateTimeUtcEnabled) {
194197
ensureCorrectStructSize(TypeConstructor.DATE_TIME, DATE_TIME_STRUCT_SIZE, size);
195198
return unpackDateTimeUtcWithZoneOffset();
199+
} else {
200+
throw instantiateExceptionForUnknownType(type);
196201
}
197202
case DATE_TIME_WITH_ZONE_ID:
198203
if (!dateTimeUtcEnabled) {
199204
ensureCorrectStructSize(TypeConstructor.DATE_TIME, DATE_TIME_STRUCT_SIZE, size);
200205
return unpackDateTimeWithZoneId();
206+
} else {
207+
throw instantiateExceptionForUnknownType(type);
201208
}
202209
case DATE_TIME_WITH_ZONE_ID_UTC:
203210
if (dateTimeUtcEnabled) {
204211
ensureCorrectStructSize(TypeConstructor.DATE_TIME, DATE_TIME_STRUCT_SIZE, size);
205212
return unpackDateTimeUtcWithZoneId();
213+
} else {
214+
throw instantiateExceptionForUnknownType(type);
206215
}
207216
case DURATION:
208217
ensureCorrectStructSize(TypeConstructor.DURATION, DURATION_TIME_STRUCT_SIZE, size);
@@ -224,7 +233,7 @@ protected Value unpackStruct(long size, byte type) throws IOException {
224233
ensureCorrectStructSize(TypeConstructor.PATH, 3, size);
225234
return unpackPath();
226235
default:
227-
throw new IOException("Unknown struct type: " + type);
236+
throw instantiateExceptionForUnknownType(type);
228237
}
229238
}
230239

@@ -417,4 +426,8 @@ private ZonedDateTime newZonedDateTimeUsingUtcBaseline(long epochSecondLocal, in
417426
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zoneId);
418427
return ZonedDateTime.of(localDateTime, zoneId);
419428
}
429+
430+
private ProtocolException instantiateExceptionForUnknownType(byte type) {
431+
return new ProtocolException("Unknown struct type: " + type);
432+
}
420433
}

0 commit comments

Comments
 (0)