Skip to content

Commit

Permalink
Do not allow mixing UTC and legacy datetime and throw ProtocolExcepti…
Browse files Browse the repository at this point in the history
…on on unknown struct types (#1260)
  • Loading branch information
injectives authored Jul 7, 2022
1 parent a2d3da8 commit 213daba
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.Map;
import org.neo4j.driver.Value;
import org.neo4j.driver.exceptions.ClientException;
import org.neo4j.driver.exceptions.ProtocolException;
import org.neo4j.driver.internal.InternalNode;
import org.neo4j.driver.internal.InternalPath;
import org.neo4j.driver.internal.InternalRelationship;
Expand Down Expand Up @@ -189,21 +190,29 @@ private Value unpackStruct(long size, byte type) throws IOException {
if (!dateTimeUtcEnabled) {
ensureCorrectStructSize(TypeConstructor.DATE_TIME, DATE_TIME_STRUCT_SIZE, size);
return unpackDateTimeWithZoneOffset();
} else {
throw instantiateExceptionForUnknownType(type);
}
case DATE_TIME_WITH_ZONE_OFFSET_UTC:
if (dateTimeUtcEnabled) {
ensureCorrectStructSize(TypeConstructor.DATE_TIME, DATE_TIME_STRUCT_SIZE, size);
return unpackDateTimeUtcWithZoneOffset();
} else {
throw instantiateExceptionForUnknownType(type);
}
case DATE_TIME_WITH_ZONE_ID:
if (!dateTimeUtcEnabled) {
ensureCorrectStructSize(TypeConstructor.DATE_TIME, DATE_TIME_STRUCT_SIZE, size);
return unpackDateTimeWithZoneId();
} else {
throw instantiateExceptionForUnknownType(type);
}
case DATE_TIME_WITH_ZONE_ID_UTC:
if (dateTimeUtcEnabled) {
ensureCorrectStructSize(TypeConstructor.DATE_TIME, DATE_TIME_STRUCT_SIZE, size);
return unpackDateTimeUtcWithZoneId();
} else {
throw instantiateExceptionForUnknownType(type);
}
case DURATION:
ensureCorrectStructSize(TypeConstructor.DURATION, DURATION_TIME_STRUCT_SIZE, size);
Expand All @@ -225,7 +234,7 @@ private Value unpackStruct(long size, byte type) throws IOException {
ensureCorrectStructSize(TypeConstructor.PATH, 3, size);
return unpackPath();
default:
throw new IOException("Unknown struct type: " + type);
throw instantiateExceptionForUnknownType(type);
}
}

Expand Down Expand Up @@ -430,6 +439,10 @@ private ZonedDateTime newZonedDateTimeUsingUtcBaseline(long epochSecondLocal, in
return ZonedDateTime.of(localDateTime, zoneId);
}

private ProtocolException instantiateExceptionForUnknownType(byte type) {
return new ProtocolException("Unknown struct type: " + type);
}

protected int getNodeFields() {
return NODE_FIELDS;
}
Expand Down

0 comments on commit 213daba

Please sign in to comment.