Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not allow mixing UTC and legacy datetime and throw ProtocolException on unknown struct types #1263

Merged
merged 1 commit into from
Jul 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -188,21 +189,29 @@ protected 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 @@ -224,7 +233,7 @@ protected 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 @@ -417,4 +426,8 @@ private ZonedDateTime newZonedDateTimeUsingUtcBaseline(long epochSecondLocal, in
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zoneId);
return ZonedDateTime.of(localDateTime, zoneId);
}

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