From df91e30e4d7e81d11c51f294b6c9c1fd5188e70b Mon Sep 17 00:00:00 2001 From: Christian Himpe Date: Sun, 29 Oct 2023 12:03:01 +0100 Subject: [PATCH 01/11] note potential np deref --- .../src/main/java/com/arcadedb/database/DocumentValidator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/src/main/java/com/arcadedb/database/DocumentValidator.java b/engine/src/main/java/com/arcadedb/database/DocumentValidator.java index 8544e0f073..db3d48a8af 100644 --- a/engine/src/main/java/com/arcadedb/database/DocumentValidator.java +++ b/engine/src/main/java/com/arcadedb/database/DocumentValidator.java @@ -102,7 +102,7 @@ public static void validateField(final MutableDocument document, final Property } else if (item instanceof EmbeddedDocument) { if (!((EmbeddedDocument) item).getType().instanceOf(ofType)) throwValidationException(p, - "has been declared as LIST of '" + ofType + "' but an embedded document of type '" + embType + "' is used. Value: " + fieldValue); + "has been declared as LIST of '" + ofType + "' but an embedded document of type '" + embType + "' is used. Value: " + fieldValue); // TODO: potential null pointer dereference } else if (item instanceof Identifiable) { final RID rid = ((Identifiable) item).getIdentity(); final DocumentType embSchemaType = document.getDatabase().getSchema().getTypeByBucketId(rid.getBucketId()); From bf20442c5e1b0942c22ff907d80a792c02c5538e Mon Sep 17 00:00:00 2001 From: Christian Himpe Date: Sun, 29 Oct 2023 12:03:51 +0100 Subject: [PATCH 02/11] note potential np deref --- .../com/arcadedb/query/sql/executor/CheckClusterTypeStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/src/main/java/com/arcadedb/query/sql/executor/CheckClusterTypeStep.java b/engine/src/main/java/com/arcadedb/query/sql/executor/CheckClusterTypeStep.java index 45c0e3982c..9aba7e05fa 100644 --- a/engine/src/main/java/com/arcadedb/query/sql/executor/CheckClusterTypeStep.java +++ b/engine/src/main/java/com/arcadedb/query/sql/executor/CheckClusterTypeStep.java @@ -57,7 +57,7 @@ public ResultSet syncPull(final CommandContext context, final int nRecords) thro if (bucketName != null) bucketObj = db.getSchema().getBucketByName(bucketName); - else if (bucket.getBucketName() != null) + else if (bucket.getBucketName() != null) // TODO: potential null pointer dereference? bucketObj = db.getSchema().getBucketByName(bucket.getBucketName()); else bucketObj = db.getSchema().getBucketById(bucket.getBucketNumber()); From f77fc0a7548e1a4bcaaf1ef8e729d22b2d9297ba Mon Sep 17 00:00:00 2001 From: Christian Himpe Date: Sun, 29 Oct 2023 12:04:23 +0100 Subject: [PATCH 03/11] add note to TODO --- .../arcadedb/query/sql/executor/TraverseExecutionPlanner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/src/main/java/com/arcadedb/query/sql/executor/TraverseExecutionPlanner.java b/engine/src/main/java/com/arcadedb/query/sql/executor/TraverseExecutionPlanner.java index 409a5b3f6d..7e3407b7a4 100644 --- a/engine/src/main/java/com/arcadedb/query/sql/executor/TraverseExecutionPlanner.java +++ b/engine/src/main/java/com/arcadedb/query/sql/executor/TraverseExecutionPlanner.java @@ -248,7 +248,7 @@ private void handleClustersAsTarget(final SelectExecutionPlan plan, final List Date: Sun, 29 Oct 2023 12:04:49 +0100 Subject: [PATCH 04/11] note potential np deref --- .../com/arcadedb/query/sql/parser/AlterPropertyStatement.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/src/main/java/com/arcadedb/query/sql/parser/AlterPropertyStatement.java b/engine/src/main/java/com/arcadedb/query/sql/parser/AlterPropertyStatement.java index 2641075f01..ac0d1f167f 100755 --- a/engine/src/main/java/com/arcadedb/query/sql/parser/AlterPropertyStatement.java +++ b/engine/src/main/java/com/arcadedb/query/sql/parser/AlterPropertyStatement.java @@ -50,7 +50,7 @@ public ResultSet executeDDL(final CommandContext context) { final DocumentType typez = db.getSchema().getType(typeName.getStringValue()); if (typez == null) - throw new CommandExecutionException("Invalid type name or type not found: " + typez); + throw new CommandExecutionException("Invalid type name or type not found: " + typez); // TODO: typez is always null here! final Property property = typez.getProperty(propertyName.getStringValue()); if (property == null) From 287078785afefe670f6863d69c35065a5cc856fa Mon Sep 17 00:00:00 2001 From: Christian Himpe Date: Sun, 29 Oct 2023 12:05:08 +0100 Subject: [PATCH 05/11] note potential np deref --- .../com/arcadedb/query/sql/parser/RebuildIndexStatement.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/src/main/java/com/arcadedb/query/sql/parser/RebuildIndexStatement.java b/engine/src/main/java/com/arcadedb/query/sql/parser/RebuildIndexStatement.java index 97bcc502e3..5a49f9aa09 100644 --- a/engine/src/main/java/com/arcadedb/query/sql/parser/RebuildIndexStatement.java +++ b/engine/src/main/java/com/arcadedb/query/sql/parser/RebuildIndexStatement.java @@ -120,7 +120,7 @@ else if (entry.getKey().toString().equalsIgnoreCase("maxAttempts")) private static void buildIndex(final int maxAttempts, Database database, Index.BuildIndexCallback callback, Index idx, final int batchSize) { if (idx == null) - throw new CommandExecutionException("Index '" + idx.getName() + "' not found"); + throw new CommandExecutionException("Index '" + idx.getName() + "' not found"); // TODO: Null pointer derefence? if (!idx.isAutomatic()) throw new CommandExecutionException( From 81976b1a34dd589a41f939a1774a9c0b715b07de Mon Sep 17 00:00:00 2001 From: Christian Himpe Date: Sun, 29 Oct 2023 12:05:32 +0100 Subject: [PATCH 06/11] remove unnecessary conditional --- engine/src/main/java/com/arcadedb/schema/DocumentType.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/engine/src/main/java/com/arcadedb/schema/DocumentType.java b/engine/src/main/java/com/arcadedb/schema/DocumentType.java index 60c92f2a1f..8d1c39cd73 100644 --- a/engine/src/main/java/com/arcadedb/schema/DocumentType.java +++ b/engine/src/main/java/com/arcadedb/schema/DocumentType.java @@ -623,9 +623,8 @@ public Collection getAllIndexes(final boolean polymorphic) { final List list = new ArrayList<>(indexesByProperties.values()); - if (polymorphic) - for (final DocumentType t : superTypes) - list.addAll(t.getAllIndexes(true)); + for (final DocumentType t : superTypes) + list.addAll(t.getAllIndexes(true)); return Collections.unmodifiableCollection(list); } From f1002cec59f88b88734639341d447df8c7934699 Mon Sep 17 00:00:00 2001 From: Christian Himpe Date: Sun, 29 Oct 2023 12:06:21 +0100 Subject: [PATCH 07/11] fix asserts in test --- .../functions/math/SQLFunctionSquareRootTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionSquareRootTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionSquareRootTest.java index d1eecdf6ef..fee5ee1cfc 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionSquareRootTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionSquareRootTest.java @@ -65,7 +65,7 @@ public void testPositiveInteger() { public void testNegativeInteger() { function.execute(null, null, null, new Object[]{-4}, null); final Object result = function.getResult(); - assertEquals(result, null); + assertNull(result); } @Test @@ -80,7 +80,7 @@ public void testPositiveLong() { public void testNegativeLong() { function.execute(null, null, null, new Object[]{-4L}, null); final Object result = function.getResult(); - assertEquals(result, null); + assertNull(result); } @Test @@ -95,7 +95,7 @@ public void testPositiveShort() { public void testNegativeShort() { function.execute(null, null, null, new Object[]{(short) -4}, null); final Object result = function.getResult(); - assertEquals(result, null); + assertNull(result); } @Test @@ -110,7 +110,7 @@ public void testPositiveDouble() { public void testNegativeDouble() { function.execute(null, null, null, new Object[]{-4.0D}, null); final Object result = function.getResult(); - assertEquals(result, null); + assertNull(result); } @Test @@ -125,7 +125,7 @@ public void testPositiveFloat() { public void testNegativeFloat() { function.execute(null, null, null, new Object[]{-4.0F}, null); final Object result = function.getResult(); - assertEquals(result, null); + assertNull(result); } @Test @@ -140,7 +140,7 @@ public void testPositiveBigDecimal() { public void testNegativeBigDecimal() { function.execute(null, null, null, new Object[]{BigDecimal.valueOf(-4.0D)}, null); final Object result = function.getResult(); - assertEquals(result, null); + assertNull(result); } @Test @@ -155,7 +155,7 @@ public void testPositiveBigInteger() { public void testNegativeBigInteger() { function.execute(null, null, null, new Object[]{new BigInteger("-4")}, null); final Object result = function.getResult(); - assertEquals(result, null); + assertNull(results); } @Test From d874a6178203aebe49c52d2dfaed1325e7537b45 Mon Sep 17 00:00:00 2001 From: Christian Himpe Date: Sun, 29 Oct 2023 12:07:03 +0100 Subject: [PATCH 08/11] note potential npe --- .../com/arcadedb/integration/exporter/ExporterSettings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/src/main/java/com/arcadedb/integration/exporter/ExporterSettings.java b/integration/src/main/java/com/arcadedb/integration/exporter/ExporterSettings.java index ea94280a5a..ecef562f7c 100644 --- a/integration/src/main/java/com/arcadedb/integration/exporter/ExporterSettings.java +++ b/integration/src/main/java/com/arcadedb/integration/exporter/ExporterSettings.java @@ -60,7 +60,7 @@ protected void parseParameters(final String[] args) { if (file == null) { final DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmssSSS"); - file = String.format(file, dateFormat.format(System.currentTimeMillis())); + file = String.format(file, dateFormat.format(System.currentTimeMillis())); // TODO: null parameter not allowed? } } From 2fd9d09bf5910ff3e8d157dff5a4c7b9c04f2e79 Mon Sep 17 00:00:00 2001 From: Christian Himpe Date: Sun, 29 Oct 2023 12:07:19 +0100 Subject: [PATCH 09/11] note potential np deref --- .../com/arcadedb/server/http/handler/DeleteDropUserHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/com/arcadedb/server/http/handler/DeleteDropUserHandler.java b/server/src/main/java/com/arcadedb/server/http/handler/DeleteDropUserHandler.java index 809614d3d0..bc7747ea2b 100644 --- a/server/src/main/java/com/arcadedb/server/http/handler/DeleteDropUserHandler.java +++ b/server/src/main/java/com/arcadedb/server/http/handler/DeleteDropUserHandler.java @@ -42,7 +42,7 @@ public ExecutionResponse execute(final HttpServerExchange exchange, final Server final Deque userNamePar = exchange.getQueryParameters().get("userName"); String userName = userNamePar.isEmpty() ? null : userNamePar.getFirst().trim(); - if (userName.isEmpty()) + if (userName.isEmpty()) // TODO: Null pointer dereference? userName = null; if (userName == null) From 268fe8c9c643e77c95a0c20c9fe48c3081e9e135 Mon Sep 17 00:00:00 2001 From: Christian Himpe Date: Sun, 29 Oct 2023 12:14:24 +0100 Subject: [PATCH 10/11] fix typo in test --- .../query/sql/functions/math/SQLFunctionSquareRootTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionSquareRootTest.java b/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionSquareRootTest.java index fee5ee1cfc..2019098c66 100644 --- a/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionSquareRootTest.java +++ b/engine/src/test/java/com/arcadedb/query/sql/functions/math/SQLFunctionSquareRootTest.java @@ -155,7 +155,7 @@ public void testPositiveBigInteger() { public void testNegativeBigInteger() { function.execute(null, null, null, new Object[]{new BigInteger("-4")}, null); final Object result = function.getResult(); - assertNull(results); + assertNull(result); } @Test From c7d9542143cc1a6f44aa875e48f844811b199d40 Mon Sep 17 00:00:00 2001 From: lvca Date: Tue, 31 Oct 2023 00:48:19 -0400 Subject: [PATCH 11/11] fix: from @gramian static code run PR Changes to #1290 --- .../arcadedb/database/DocumentValidator.java | 37 +++++--- .../sql/executor/CheckClusterTypeStep.java | 14 ++- .../executor/TraverseExecutionPlanner.java | 43 +++++---- .../sql/parser/AlterPropertyStatement.java | 2 +- .../sql/parser/RebuildIndexStatement.java | 2 +- .../com/arcadedb/schema/DocumentType.java | 92 +++++++++++-------- .../exporter/ExporterSettings.java | 12 +-- .../http/handler/DeleteDropUserHandler.java | 2 +- 8 files changed, 115 insertions(+), 89 deletions(-) diff --git a/engine/src/main/java/com/arcadedb/database/DocumentValidator.java b/engine/src/main/java/com/arcadedb/database/DocumentValidator.java index db3d48a8af..f921da2672 100644 --- a/engine/src/main/java/com/arcadedb/database/DocumentValidator.java +++ b/engine/src/main/java/com/arcadedb/database/DocumentValidator.java @@ -50,7 +50,9 @@ public static void validateField(final MutableDocument document, final Property if (p.getRegexp() != null) // REGEXP if (!(fieldValue.toString()).matches(p.getRegexp())) - throwValidationException(p, "does not match the regular expression '" + p.getRegexp() + "'. Field value is: " + fieldValue + ", record: " + document); + throwValidationException(p, + "does not match the regular expression '" + p.getRegexp() + "'. Field value is: " + fieldValue + ", record: " + + document); final Type propertyType = p.getType(); @@ -67,7 +69,9 @@ public static void validateField(final MutableDocument document, final Property final RID rid = ((Identifiable) fieldValue).getIdentity(); final DocumentType embSchemaType = document.getDatabase().getSchema().getTypeByBucketId(rid.getBucketId()); if (!embSchemaType.instanceOf(ofType)) - throwValidationException(p, "has been declared as LINK of '" + ofType + "' but a link to type '" + embSchemaType + "' is used. Value: " + fieldValue); + throwValidationException(p, + "has been declared as LINK of '" + ofType + "' but a link to type '" + embSchemaType + "' is used. Value: " + + fieldValue); } } break; @@ -80,7 +84,8 @@ public static void validateField(final MutableDocument document, final Property final DocumentType embSchemaType = ((EmbeddedDocument) fieldValue).getType(); if (!embSchemaType.instanceOf(ofType)) throwValidationException(p, - "has been declared as EMBEDDED of '" + ofType + "' but a document of type '" + embSchemaType + "' is used. Value: " + fieldValue); + "has been declared as EMBEDDED of '" + ofType + "' but a document of type '" + embSchemaType + + "' is used. Value: " + fieldValue); } if (fieldValue instanceof MutableEmbeddedDocument) ((MutableEmbeddedDocument) fieldValue).validate(); @@ -98,17 +103,19 @@ public static void validateField(final MutableDocument document, final Property if (embType != null) { if (Type.getTypeByValue(item) != embType) throwValidationException(p, - "has been declared as LIST of '" + ofType + "' but a value of type '" + Type.getTypeByValue(item) + "' is used. Value: " + fieldValue); + "has been declared as LIST of '" + ofType + "' but a value of type '" + Type.getTypeByValue(item) + + "' is used. Value: " + fieldValue); } else if (item instanceof EmbeddedDocument) { if (!((EmbeddedDocument) item).getType().instanceOf(ofType)) - throwValidationException(p, - "has been declared as LIST of '" + ofType + "' but an embedded document of type '" + embType + "' is used. Value: " + fieldValue); // TODO: potential null pointer dereference + throwValidationException(p, "has been declared as LIST of '" + ofType + "' but an embedded document of type '" + + ((EmbeddedDocument) item).getType().getName() + "' is used. Value: " + fieldValue); } else if (item instanceof Identifiable) { final RID rid = ((Identifiable) item).getIdentity(); final DocumentType embSchemaType = document.getDatabase().getSchema().getTypeByBucketId(rid.getBucketId()); if (!embSchemaType.instanceOf(ofType)) throwValidationException(p, - "has been declared as LIST of '" + ofType + "' but a link to type '" + embSchemaType + "' is used. Value: " + fieldValue); + "has been declared as LIST of '" + ofType + "' but a link to type '" + embSchemaType + "' is used. Value: " + + fieldValue); } } @@ -129,18 +136,20 @@ public static void validateField(final MutableDocument document, final Property if (embType != null) { if (Type.getTypeByValue(item) != embType) throwValidationException(p, - "has been declared as MAP of but a value of type '" + Type.getTypeByValue(item) + "' is used. Value: " - + fieldValue); + "has been declared as MAP of but a value of type '" + Type.getTypeByValue(item) + + "' is used. Value: " + fieldValue); } else if (item instanceof EmbeddedDocument) { if (!((EmbeddedDocument) item).getType().instanceOf(ofType)) throwValidationException(p, - "has been declared as MAP of but an embedded document of type '" + embType + "' is used. Value: " + fieldValue); + "has been declared as MAP of but an embedded document of type '" + embType + + "' is used. Value: " + fieldValue); } else if (item instanceof Identifiable) { final RID rid = ((Identifiable) item).getIdentity(); final DocumentType embSchemaType = document.getDatabase().getSchema().getTypeByBucketId(rid.getBucketId()); if (!embSchemaType.instanceOf(ofType)) throwValidationException(p, - "has been declared as LIST of '" + ofType + "' but a link to type '" + embType + "' is used. Value: " + fieldValue); + "has been declared as LIST of '" + ofType + "' but a link to type '" + embType + "' is used. Value: " + + fieldValue); } } @@ -220,7 +229,8 @@ public static void validateField(final MutableDocument document, final Property final Date fieldValueAsDate = (Date) Type.convert(database, fieldValue, Date.class); if (fieldValueAsDate.compareTo(minAsDate) < 0) - throwValidationException(p, "contains the date " + fieldValue + " which precedes the first acceptable date (" + min + ")"); + throwValidationException(p, + "contains the date " + fieldValue + " which precedes the first acceptable date (" + min + ")"); break; } @@ -321,7 +331,8 @@ public static void validateField(final MutableDocument document, final Property final Date fieldValueAsDate = (Date) Type.convert(database, fieldValue, Date.class); if (fieldValueAsDate.compareTo(maxAsDate) > 0) - throwValidationException(p, "contains the date " + fieldValue + " which is after the last acceptable date (" + max + ")"); + throwValidationException(p, + "contains the date " + fieldValue + " which is after the last acceptable date (" + max + ")"); break; } diff --git a/engine/src/main/java/com/arcadedb/query/sql/executor/CheckClusterTypeStep.java b/engine/src/main/java/com/arcadedb/query/sql/executor/CheckClusterTypeStep.java index 9aba7e05fa..723f01eccd 100644 --- a/engine/src/main/java/com/arcadedb/query/sql/executor/CheckClusterTypeStep.java +++ b/engine/src/main/java/com/arcadedb/query/sql/executor/CheckClusterTypeStep.java @@ -37,7 +37,8 @@ public class CheckClusterTypeStep extends AbstractExecutionStep { final String targetType; boolean found = false; - public CheckClusterTypeStep(final String targetBucketName, final String typez, final CommandContext context, final boolean profilingEnabled) { + public CheckClusterTypeStep(final String targetBucketName, final String typez, final CommandContext context, + final boolean profilingEnabled) { super(context, profilingEnabled); this.bucketName = targetBucketName; this.bucket = null; @@ -57,10 +58,13 @@ public ResultSet syncPull(final CommandContext context, final int nRecords) thro if (bucketName != null) bucketObj = db.getSchema().getBucketByName(bucketName); - else if (bucket.getBucketName() != null) // TODO: potential null pointer dereference? - bucketObj = db.getSchema().getBucketByName(bucket.getBucketName()); - else - bucketObj = db.getSchema().getBucketById(bucket.getBucketNumber()); + else if (bucket != null) { + if (bucket.getBucketName() != null) + bucketObj = db.getSchema().getBucketByName(bucket.getBucketName()); + else + bucketObj = db.getSchema().getBucketById(bucket.getBucketNumber()); + } else + bucketObj = null; if (bucketObj == null) throw new CommandExecutionException("Bucket not found: " + bucketName); diff --git a/engine/src/main/java/com/arcadedb/query/sql/executor/TraverseExecutionPlanner.java b/engine/src/main/java/com/arcadedb/query/sql/executor/TraverseExecutionPlanner.java index 7e3407b7a4..7bfa7c3d2a 100644 --- a/engine/src/main/java/com/arcadedb/query/sql/executor/TraverseExecutionPlanner.java +++ b/engine/src/main/java/com/arcadedb/query/sql/executor/TraverseExecutionPlanner.java @@ -56,7 +56,9 @@ public class TraverseExecutionPlanner { public TraverseExecutionPlanner(final TraverseStatement statement) { //copying the content, so that it can be manipulated and optimized - this.projections = statement.getProjections() == null ? null : statement.getProjections().stream().map(x -> x.copy()).collect(Collectors.toList()); + this.projections = statement.getProjections() == null ? + null : + statement.getProjections().stream().map(x -> x.copy()).collect(Collectors.toList()); this.target = statement.getTarget(); this.whileClause = statement.getWhileClause() == null ? null : statement.getWhileClause().copy(); @@ -97,7 +99,8 @@ private void handleTraversal(final SelectExecutionPlan result, final CommandCont //TODO } - private void handleFetchFromTarget(final SelectExecutionPlan result, final CommandContext context, final boolean profilingEnabled) { + private void handleFetchFromTarget(final SelectExecutionPlan result, final CommandContext context, + final boolean profilingEnabled) { final FromItem target = this.target == null ? null : this.target.getItem(); if (target == null) { @@ -126,8 +129,8 @@ private void handleFetchFromTarget(final SelectExecutionPlan result, final Comma } } - private void handleInputParamAsTarget(final SelectExecutionPlan result, final InputParameter inputParam, final CommandContext context, - final boolean profilingEnabled) { + private void handleInputParamAsTarget(final SelectExecutionPlan result, final InputParameter inputParam, + final CommandContext context, final boolean profilingEnabled) { final Object paramValue = inputParam.getValue(context.getInputParameters()); if (paramValue == null) { result.chain(new EmptyStep(context, profilingEnabled));//nothing to return @@ -186,8 +189,8 @@ private void handleNoTarget(final SelectExecutionPlan result, final CommandConte result.chain(new EmptyDataGeneratorStep(1, context, profilingEnabled)); } - private void handleIndexAsTarget(final SelectExecutionPlan result, final IndexIdentifier indexIdentifier, final CommandContext context, - final boolean profilingEnabled) { + private void handleIndexAsTarget(final SelectExecutionPlan result, final IndexIdentifier indexIdentifier, + final CommandContext context, final boolean profilingEnabled) { final String indexName = indexIdentifier.getIndexName(); final RangeIndex index = (RangeIndex) context.getDatabase().getSchema().getIndexByName(indexName); if (index == null) { @@ -220,7 +223,8 @@ private void handleIndexAsTarget(final SelectExecutionPlan result, final IndexId } } - private void handleRidsAsTarget(final SelectExecutionPlan plan, final List rids, final CommandContext context, final boolean profilingEnabled) { + private void handleRidsAsTarget(final SelectExecutionPlan plan, final List rids, final CommandContext context, + final boolean profilingEnabled) { final List actualRids = new ArrayList<>(); for (final Rid rid : rids) { actualRids.add(rid.toRecordId((Result) null, context)); @@ -228,49 +232,44 @@ private void handleRidsAsTarget(final SelectExecutionPlan plan, final List plan.chain(new FetchFromRidsStep(actualRids, context, profilingEnabled)); } - private void handleClassAsTarget(final SelectExecutionPlan plan, final FromClause queryTarget, final CommandContext context, final boolean profilingEnabled) { + private void handleClassAsTarget(final SelectExecutionPlan plan, final FromClause queryTarget, final CommandContext context, + final boolean profilingEnabled) { final Identifier identifier = queryTarget.getItem().getIdentifier(); final Boolean orderByRidAsc = null;//null: no order. true: asc, false:desc - final FetchFromClassExecutionStep fetcher = new FetchFromClassExecutionStep(identifier.getStringValue(), null, context, orderByRidAsc, profilingEnabled); + final FetchFromClassExecutionStep fetcher = new FetchFromClassExecutionStep(identifier.getStringValue(), null, context, + orderByRidAsc, profilingEnabled); plan.chain(fetcher); } private void handleClustersAsTarget(final SelectExecutionPlan plan, final List clusters, final CommandContext context, final boolean profilingEnabled) { final Database db = context.getDatabase(); - final Boolean orderByRidAsc = null;//null: no order. true: asc, false:desc if (clusters.size() == 1) { final Bucket bucket = clusters.get(0); Integer bucketId = bucket.getBucketNumber(); - if (bucketId == null) { + if (bucketId == null) bucketId = db.getSchema().getBucketByName(bucket.getBucketName()).getFileId(); - } final FetchFromClusterExecutionStep step = new FetchFromClusterExecutionStep(bucketId, context, profilingEnabled); - // TODO: THIS SEEMS A BUG (maybe because if null is passed equals always returns false?) - if (Boolean.TRUE.equals(orderByRidAsc)) { - step.setOrder(FetchFromClusterExecutionStep.ORDER_ASC); - } else if (Boolean.FALSE.equals(orderByRidAsc)) { - step.setOrder(FetchFromClusterExecutionStep.ORDER_DESC); - } plan.chain(step); } else { final int[] bucketIds = new int[clusters.size()]; for (int i = 0; i < clusters.size(); i++) { final Bucket bucket = clusters.get(i); Integer bucketId = bucket.getBucketNumber(); - if (bucketId == null) { + if (bucketId == null) bucketId = db.getSchema().getBucketByName(bucket.getBucketName()).getFileId(); - } + bucketIds[i] = bucketId; } - final FetchFromClustersExecutionStep step = new FetchFromClustersExecutionStep(bucketIds, context, orderByRidAsc, profilingEnabled); + final FetchFromClustersExecutionStep step = new FetchFromClustersExecutionStep(bucketIds, context, null, profilingEnabled); plan.chain(step); } } - private void handleSubqueryAsTarget(final SelectExecutionPlan plan, final Statement subQuery, final CommandContext context, final boolean profilingEnabled) { + private void handleSubqueryAsTarget(final SelectExecutionPlan plan, final Statement subQuery, final CommandContext context, + final boolean profilingEnabled) { final BasicCommandContext subCtx = new BasicCommandContext(); subCtx.setDatabase(context.getDatabase()); subCtx.setParent(context); diff --git a/engine/src/main/java/com/arcadedb/query/sql/parser/AlterPropertyStatement.java b/engine/src/main/java/com/arcadedb/query/sql/parser/AlterPropertyStatement.java index ac0d1f167f..11366da3f0 100755 --- a/engine/src/main/java/com/arcadedb/query/sql/parser/AlterPropertyStatement.java +++ b/engine/src/main/java/com/arcadedb/query/sql/parser/AlterPropertyStatement.java @@ -50,7 +50,7 @@ public ResultSet executeDDL(final CommandContext context) { final DocumentType typez = db.getSchema().getType(typeName.getStringValue()); if (typez == null) - throw new CommandExecutionException("Invalid type name or type not found: " + typez); // TODO: typez is always null here! + throw new CommandExecutionException("Type name is null"); final Property property = typez.getProperty(propertyName.getStringValue()); if (property == null) diff --git a/engine/src/main/java/com/arcadedb/query/sql/parser/RebuildIndexStatement.java b/engine/src/main/java/com/arcadedb/query/sql/parser/RebuildIndexStatement.java index 5a49f9aa09..c8ba055655 100644 --- a/engine/src/main/java/com/arcadedb/query/sql/parser/RebuildIndexStatement.java +++ b/engine/src/main/java/com/arcadedb/query/sql/parser/RebuildIndexStatement.java @@ -120,7 +120,7 @@ else if (entry.getKey().toString().equalsIgnoreCase("maxAttempts")) private static void buildIndex(final int maxAttempts, Database database, Index.BuildIndexCallback callback, Index idx, final int batchSize) { if (idx == null) - throw new CommandExecutionException("Index '" + idx.getName() + "' not found"); // TODO: Null pointer derefence? + throw new CommandExecutionException("Index name is null"); if (!idx.isAutomatic()) throw new CommandExecutionException( diff --git a/engine/src/main/java/com/arcadedb/schema/DocumentType.java b/engine/src/main/java/com/arcadedb/schema/DocumentType.java index 8d1c39cd73..f2471eb364 100644 --- a/engine/src/main/java/com/arcadedb/schema/DocumentType.java +++ b/engine/src/main/java/com/arcadedb/schema/DocumentType.java @@ -107,7 +107,8 @@ protected DocumentType addSuperType(final DocumentType superType, final boolean final Set allProperties = getPolymorphicPropertyNames(); for (final String p : superType.getPolymorphicPropertyNames()) if (allProperties.contains(p)) { - LogManager.instance().log(this, Level.WARNING, "Property '" + p + "' is already defined in type '" + name + "' or any super types"); + LogManager.instance() + .log(this, Level.WARNING, "Property '" + p + "' is already defined in type '" + name + "' or any super types"); //throw new IllegalArgumentException("Property '" + p + "' is already defined in type '" + name + "' or any super types"); } @@ -127,20 +128,22 @@ protected DocumentType addSuperType(final DocumentType superType, final boolean schema.getDatabase().transaction(() -> { for (final TypeIndex index : indexes) { if (index.getType() == null) { - LogManager.instance() - .log(this, Level.WARNING, "Error on creating implicit indexes from super type '" + superType.getName() + "': key types is null"); + LogManager.instance().log(this, Level.WARNING, + "Error on creating implicit indexes from super type '" + superType.getName() + "': key types is null"); } else { for (int i = 0; i < buckets.size(); i++) { final Bucket bucket = buckets.get(i); - schema.createBucketIndex(this, index.getKeyTypes(), bucket, name, index.getType(), index.isUnique(), LSMTreeIndexAbstract.DEF_PAGE_SIZE, - index.getNullStrategy(), null, index.getPropertyNames().toArray(new String[index.getPropertyNames().size()]), index, + schema.createBucketIndex(this, index.getKeyTypes(), bucket, name, index.getType(), index.isUnique(), + LSMTreeIndexAbstract.DEF_PAGE_SIZE, index.getNullStrategy(), null, + index.getPropertyNames().toArray(new String[index.getPropertyNames().size()]), index, IndexBuilder.BUILD_BATCH_SIZE); } } } }, false); } catch (final IndexException e) { - LogManager.instance().log(this, Level.WARNING, "Error on creating implicit indexes from super type '" + superType.getName() + "'", e); + LogManager.instance() + .log(this, Level.WARNING, "Error on creating implicit indexes from super type '" + superType.getName() + "'", e); throw e; } } @@ -360,10 +363,12 @@ public Property createProperty(final String propertyName, final Type propertyTyp */ public Property createProperty(final String propertyName, final Type propertyType, final String ofType) { if (properties.containsKey(propertyName)) - throw new SchemaException("Cannot create the property '" + propertyName + "' in type '" + name + "' because it already exists"); + throw new SchemaException( + "Cannot create the property '" + propertyName + "' in type '" + name + "' because it already exists"); if (getPolymorphicPropertyNames().contains(propertyName)) - throw new SchemaException("Cannot create the property '" + propertyName + "' in type '" + name + "' because it was already defined in a super type"); + throw new SchemaException("Cannot create the property '" + propertyName + "' in type '" + name + + "' because it was already defined in a super type"); final Property property = new Property(this, propertyName, propertyType); @@ -447,7 +452,8 @@ public Property getOrCreateProperty(final String propertyName, final Type proper public Property dropProperty(final String propertyName) { for (final TypeIndex index : getAllIndexes(true)) { if (index.getPropertyNames().contains(propertyName)) - throw new SchemaException("Error on dropping property '" + propertyName + "' because used by index '" + index.getName() + "'"); + throw new SchemaException( + "Error on dropping property '" + propertyName + "' because used by index '" + index.getName() + "'"); } return recordFileChanges(() -> { @@ -459,41 +465,47 @@ public TypeIndex createTypeIndex(final EmbeddedSchema.INDEX_TYPE indexType, fina return schema.buildTypeIndex(name, propertyNames).withType(indexType).withUnique(unique).create(); } - public TypeIndex createTypeIndex(final EmbeddedSchema.INDEX_TYPE indexType, final boolean unique, final String[] propertyNames, final int pageSize) { + public TypeIndex createTypeIndex(final EmbeddedSchema.INDEX_TYPE indexType, final boolean unique, final String[] propertyNames, + final int pageSize) { return schema.buildTypeIndex(name, propertyNames).withType(indexType).withUnique(unique).withPageSize(pageSize).create(); } - public TypeIndex createTypeIndex(final EmbeddedSchema.INDEX_TYPE indexType, final boolean unique, final String[] propertyNames, final int pageSize, - final Index.BuildIndexCallback callback) { - return schema.buildTypeIndex(name, propertyNames).withType(indexType).withUnique(unique).withPageSize(pageSize).withCallback(callback).create(); - } - - public TypeIndex createTypeIndex(final EmbeddedSchema.INDEX_TYPE indexType, final boolean unique, final String[] propertyNames, final int pageSize, - final LSMTreeIndexAbstract.NULL_STRATEGY nullStrategy, final Index.BuildIndexCallback callback) { - return schema.buildTypeIndex(name, propertyNames).withType(indexType).withUnique(unique).withPageSize(pageSize).withNullStrategy(nullStrategy) + public TypeIndex createTypeIndex(final EmbeddedSchema.INDEX_TYPE indexType, final boolean unique, final String[] propertyNames, + final int pageSize, final Index.BuildIndexCallback callback) { + return schema.buildTypeIndex(name, propertyNames).withType(indexType).withUnique(unique).withPageSize(pageSize) .withCallback(callback).create(); } - public TypeIndex getOrCreateTypeIndex(final EmbeddedSchema.INDEX_TYPE indexType, final boolean unique, final String... propertyNames) { - return schema.buildTypeIndex(name, propertyNames).withType(indexType).withUnique(unique).withIgnoreIfExists(true).create(); + public TypeIndex createTypeIndex(final EmbeddedSchema.INDEX_TYPE indexType, final boolean unique, final String[] propertyNames, + final int pageSize, final LSMTreeIndexAbstract.NULL_STRATEGY nullStrategy, final Index.BuildIndexCallback callback) { + return schema.buildTypeIndex(name, propertyNames).withType(indexType).withUnique(unique).withPageSize(pageSize) + .withNullStrategy(nullStrategy).withCallback(callback).create(); } - public TypeIndex getOrCreateTypeIndex(final EmbeddedSchema.INDEX_TYPE indexType, final boolean unique, final String[] propertyNames, final int pageSize) { - return schema.buildTypeIndex(name, propertyNames).withType(indexType).withUnique(unique).withPageSize(pageSize).withIgnoreIfExists(true).create(); + public TypeIndex getOrCreateTypeIndex(final EmbeddedSchema.INDEX_TYPE indexType, final boolean unique, + final String... propertyNames) { + return schema.buildTypeIndex(name, propertyNames).withType(indexType).withUnique(unique).withIgnoreIfExists(true).create(); } - public TypeIndex getOrCreateTypeIndex(final EmbeddedSchema.INDEX_TYPE indexType, final boolean unique, final String[] propertyNames, final int pageSize, - final Index.BuildIndexCallback callback) { - return schema.buildTypeIndex(name, propertyNames).withType(indexType).withUnique(unique).withPageSize(pageSize).withCallback(callback) + public TypeIndex getOrCreateTypeIndex(final EmbeddedSchema.INDEX_TYPE indexType, final boolean unique, + final String[] propertyNames, final int pageSize) { + return schema.buildTypeIndex(name, propertyNames).withType(indexType).withUnique(unique).withPageSize(pageSize) .withIgnoreIfExists(true).create(); } - public TypeIndex getOrCreateTypeIndex(final EmbeddedSchema.INDEX_TYPE indexType, final boolean unique, final String[] propertyNames, final int pageSize, - final LSMTreeIndexAbstract.NULL_STRATEGY nullStrategy, final Index.BuildIndexCallback callback) { - return schema.buildTypeIndex(name, propertyNames).withType(indexType).withUnique(unique).withPageSize(pageSize).withNullStrategy(nullStrategy) + public TypeIndex getOrCreateTypeIndex(final EmbeddedSchema.INDEX_TYPE indexType, final boolean unique, + final String[] propertyNames, final int pageSize, final Index.BuildIndexCallback callback) { + return schema.buildTypeIndex(name, propertyNames).withType(indexType).withUnique(unique).withPageSize(pageSize) .withCallback(callback).withIgnoreIfExists(true).create(); } + public TypeIndex getOrCreateTypeIndex(final EmbeddedSchema.INDEX_TYPE indexType, final boolean unique, + final String[] propertyNames, final int pageSize, final LSMTreeIndexAbstract.NULL_STRATEGY nullStrategy, + final Index.BuildIndexCallback callback) { + return schema.buildTypeIndex(name, propertyNames).withType(indexType).withUnique(unique).withPageSize(pageSize) + .withNullStrategy(nullStrategy).withCallback(callback).withIgnoreIfExists(true).create(); + } + public List getInvolvedBuckets() { return getBuckets(false); } @@ -530,7 +542,8 @@ public Bucket getBucketIdByRecord(final Document record, final boolean async) { public int getBucketIndexByKeys(final Object[] keys, final boolean async) { if (buckets.isEmpty()) - throw new SchemaException("Cannot retrieve a bucket for keys '" + Arrays.toString(keys) + "' because there are no buckets associated"); + throw new SchemaException( + "Cannot retrieve a bucket for keys '" + Arrays.toString(keys) + "' because there are no buckets associated"); return bucketSelectionStrategy.getBucketIdByKeys(keys, async); } @@ -557,7 +570,8 @@ else if (selectionStrategyName.equalsIgnoreCase("partitioned")) { selectionStrategy = new PartitionedBucketSelectionStrategy(convertedParams); } else if (selectionStrategyName.startsWith("partitioned(") && selectionStrategyName.endsWith(")")) { - final String[] params = selectionStrategyName.substring("partitioned(".length(), selectionStrategyName.length() - 1).split(","); + final String[] params = selectionStrategyName.substring("partitioned(".length(), selectionStrategyName.length() - 1) + .split(","); final List convertedParams = new ArrayList<>(params.length); for (int i = 0; i < params.length; i++) convertedParams.add(FileUtils.getStringContent(params[i])); @@ -826,7 +840,8 @@ public int hashCode() { return Objects.hash(name); } - protected void addIndexInternal(final IndexInternal index, final int bucketId, final String[] propertyNames, TypeIndex propIndex) { + protected void addIndexInternal(final IndexInternal index, final int bucketId, final String[] propertyNames, + TypeIndex propIndex) { index.setMetadata(name, propertyNames, bucketId); final List list = bucketIndexesByBucket.computeIfAbsent(bucketId, k -> new ArrayList<>()); @@ -876,9 +891,8 @@ public void removeBucketIndexInternal(final Index index) { protected void addBucketInternal(final Bucket bucket) { for (final DocumentType cl : schema.getTypes()) { if (cl.hasBucket(bucket.getName())) - throw new SchemaException( - "Cannot add the bucket '" + bucket.getName() + "' to the type '" + name + "', because the bucket is already associated to the type '" + cl.getName() - + "'"); + throw new SchemaException("Cannot add the bucket '" + bucket.getName() + "' to the type '" + name + + "', because the bucket is already associated to the type '" + cl.getName() + "'"); } buckets = CollectionUtils.addToUnmodifiableList(buckets, bucket); @@ -895,8 +909,9 @@ protected void addBucketInternal(final Bucket bucket) { if (!existentIndexes.isEmpty()) { schema.getDatabase().transaction(() -> { for (TypeIndex idx : existentIndexes) { - schema.createBucketIndex(this, idx.getKeyTypes(), bucket, name, idx.getType(), idx.isUnique(), idx.getPageSize(), idx.getNullStrategy(), null, - idx.getPropertyNames().toArray(new String[idx.getPropertyNames().size()]), idx, IndexBuilder.BUILD_BATCH_SIZE); + schema.createBucketIndex(this, idx.getKeyTypes(), bucket, name, idx.getType(), idx.isUnique(), idx.getPageSize(), + idx.getNullStrategy(), null, idx.getPropertyNames().toArray(new String[idx.getPropertyNames().size()]), idx, + IndexBuilder.BUILD_BATCH_SIZE); } }); } @@ -904,9 +919,8 @@ protected void addBucketInternal(final Bucket bucket) { protected void removeBucketInternal(final Bucket bucket) { if (!buckets.contains(bucket)) - throw new SchemaException( - "Cannot remove the bucket '" + bucket.getName() + "' to the type '" + name + "', because the bucket is not associated to the type '" + getName() - + "'"); + throw new SchemaException("Cannot remove the bucket '" + bucket.getName() + "' to the type '" + name + + "', because the bucket is not associated to the type '" + getName() + "'"); buckets = CollectionUtils.removeFromUnmodifiableList(buckets, bucket); cachedPolymorphicBuckets = CollectionUtils.removeFromUnmodifiableList(cachedPolymorphicBuckets, bucket); diff --git a/integration/src/main/java/com/arcadedb/integration/exporter/ExporterSettings.java b/integration/src/main/java/com/arcadedb/integration/exporter/ExporterSettings.java index ecef562f7c..1cc49e303a 100644 --- a/integration/src/main/java/com/arcadedb/integration/exporter/ExporterSettings.java +++ b/integration/src/main/java/com/arcadedb/integration/exporter/ExporterSettings.java @@ -50,18 +50,16 @@ protected void parseParameters(final String[] args) { if (file == null) // ASSIGN DEFAULT FILENAME switch (format) { - case "jsonl": - file = "arcadedb-export-%s.jsonl.tgz"; - break; case "backup": file = "arcadedb-backup-%s.zip"; break; + default: + file = "arcadedb-backup-%s." + format + ".tgz"; + break; } - if (file == null) { - final DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmssSSS"); - file = String.format(file, dateFormat.format(System.currentTimeMillis())); // TODO: null parameter not allowed? - } + final DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmssSSS"); + file = String.format(file, dateFormat.format(System.currentTimeMillis())); } public int parseParameter(String name, final String value) { diff --git a/server/src/main/java/com/arcadedb/server/http/handler/DeleteDropUserHandler.java b/server/src/main/java/com/arcadedb/server/http/handler/DeleteDropUserHandler.java index bc7747ea2b..5fa024af53 100644 --- a/server/src/main/java/com/arcadedb/server/http/handler/DeleteDropUserHandler.java +++ b/server/src/main/java/com/arcadedb/server/http/handler/DeleteDropUserHandler.java @@ -42,7 +42,7 @@ public ExecutionResponse execute(final HttpServerExchange exchange, final Server final Deque userNamePar = exchange.getQueryParameters().get("userName"); String userName = userNamePar.isEmpty() ? null : userNamePar.getFirst().trim(); - if (userName.isEmpty()) // TODO: Null pointer dereference? + if (userName != null && userName.isEmpty()) userName = null; if (userName == null)