Skip to content

Commit 1e4a811

Browse files
authored
Merge pull request #471 from weaviate/v6-assertions
v6: Replace assertions with exceptions where necessary
2 parents 767ce18 + b47fd71 commit 1e4a811

7 files changed

Lines changed: 22 additions & 13 deletions

File tree

src/main/java/io/weaviate/client6/v1/api/collections/Vectors.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ public Vectors read(JsonReader in) throws IOException {
186186
vector = float_1d.fromJsonTree(array);
187187
}
188188

189-
assert (vector instanceof float[]) || (vector instanceof float[][]) : "invalid vector type";
189+
assert (vector instanceof float[]) || (vector instanceof float[][])
190+
: "invalid vector type " + vector.getClass();
191+
190192
namedVectors.put(vectorName, vector);
191193
}
192194
}

src/main/java/io/weaviate/client6/v1/api/collections/aggregate/AggregateRequest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import java.util.HashMap;
55
import java.util.Map;
66

7-
import io.weaviate.client6.v1.internal.DateUtil;
87
import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults;
8+
import io.weaviate.client6.v1.internal.DateUtil;
99
import io.weaviate.client6.v1.internal.grpc.Rpc;
1010
import io.weaviate.client6.v1.internal.grpc.protocol.WeaviateGrpc.WeaviateBlockingStub;
1111
import io.weaviate.client6.v1.internal.grpc.protocol.WeaviateGrpc.WeaviateFutureStub;
@@ -79,7 +79,7 @@ static <T> Rpc<AggregateRequest, WeaviateProtoAggregate.AggregateRequest, Aggreg
7979
} else if (groupBy.hasBooleans()) {
8080
groupedBy = new GroupedBy<>(property, groupBy.getBooleans().getValuesList().toArray(Boolean[]::new));
8181
} else {
82-
assert false : "(aggregate) branch not covered";
82+
throw new IllegalArgumentException(property + " data type is not supported");
8383
}
8484

8585
var properties = unmarshalAggregation(result.getAggregations());
@@ -148,7 +148,7 @@ private static Map<String, Object> unmarshalAggregation(WeaviateProtoAggregate.A
148148
metric.hasMode() ? metric.getMode() : null,
149149
metric.hasSum() ? metric.getSum() : null);
150150
} else {
151-
assert false : "branch not covered";
151+
throw new IllegalArgumentException(property + " data type is not supported");
152152
}
153153

154154
if (value != null) {

src/main/java/io/weaviate/client6/v1/api/collections/pagination/AsyncPage.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ public CompletableFuture<AsyncPage<PropertiesT>> fetchNextPage() {
6161
// If it is null after the first iteration it is
6262
// because we haven't requested Metadata.UUID, in which
6363
// case pagination will continue to run unbounded.
64-
assert nextCursor != null : "page cursor is null";
64+
if (nextCursor == null) {
65+
throw new IllegalStateException("page cursor is null");
66+
}
6567
return new AsyncPage<>(nextCursor, pageSize, fetch, nextPage);
6668
});
6769
}

src/main/java/io/weaviate/client6/v1/api/collections/pagination/CursorSpliterator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ public boolean tryAdvance(Consumer<? super WeaviateObject<PropertiesT, Object, Q
4545
// If it is null after the first iteration it is
4646
// because we haven't requested Metadata.UUID, in which
4747
// case pagination will continue to run unbounded.
48-
assert cursor != null : "page cursor is null";
48+
if (cursor == null) {
49+
throw new IllegalStateException("page cursor is null");
50+
}
4951

5052
currentPage = nextPage.iterator();
5153
return tryAdvance(action);

src/main/java/io/weaviate/client6/v1/api/collections/query/QueryRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ private static <T> void setProperty(String property, WeaviateProtoProperties.Val
256256
builder.setOffsetDateTimeArray(property, dates);
257257
}
258258
} else {
259-
assert false : "(query) branch not covered";
259+
throw new IllegalArgumentException(property + " data type is not supported");
260260
}
261261
}
262262
}

src/main/java/io/weaviate/client6/v1/internal/orm/PojoDescriptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private ObjectBuilder<CollectionConfig> inspectClass(CollectionConfig.Builder b)
147147
}
148148

149149
if (ctor == null) {
150-
throw new IllegalArgumentException(type.getCanonicalName() + " fields are not supported");
150+
throw new IllegalArgumentException(type.getCanonicalName() + " property is not supported");
151151
}
152152

153153
assert ctor != null;

src/main/java/io/weaviate/client6/v1/internal/orm/PojoReader.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ public Map<String, Object> readProperties() {
1515
var out = new HashMap<String, Object>();
1616
for (var field : properties.getClass().getDeclaredFields()) {
1717
var propertyName = PojoDescriptor.propertyName(field);
18-
field.setAccessible(true);
19-
try {
20-
out.put(propertyName, field.get(properties));
21-
} catch (IllegalAccessException e) {
22-
assert e == null : e.getMessage();
18+
if (field.trySetAccessible()) {
19+
try {
20+
out.put(propertyName, field.get(properties));
21+
} catch (IllegalAccessException e) {
22+
new RuntimeException("accessible flag set but access denied", e);
23+
}
2324
}
25+
// TODO: how do we handle the case where a property is not accessible?
26+
// E.g. we weren't able to set `accessible` flag.
2427
}
2528
return out;
2629
}

0 commit comments

Comments
 (0)