From 31eb15a6fcd3aec468ff970e8c463c816ae4a247 Mon Sep 17 00:00:00 2001 From: Oleg Smelov Date: Thu, 29 Feb 2024 13:46:03 +0100 Subject: [PATCH] NPE fix gradle plugin updated --- build.gradle | 4 +-- .../AbstractMessageIteratorProvider.java | 29 ++++++++++--------- .../MessageBatchesIteratorProvider.java | 9 +++--- .../messages/MessagesIteratorProvider.java | 12 ++++---- gradle.properties | 2 +- 5 files changed, 27 insertions(+), 29 deletions(-) diff --git a/build.gradle b/build.gradle index 3e6072d0c..0e7371513 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { - id "io.github.gradle-nexus.publish-plugin" version "1.0.0" - id "org.owasp.dependencycheck" version "8.2.1" + id "io.github.gradle-nexus.publish-plugin" version "1.3.0" + id "org.owasp.dependencycheck" version "9.0.9" id 'signing' } diff --git a/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/messages/AbstractMessageIteratorProvider.java b/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/messages/AbstractMessageIteratorProvider.java index aac8d6552..3acd10577 100644 --- a/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/messages/AbstractMessageIteratorProvider.java +++ b/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/messages/AbstractMessageIteratorProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2023 Exactpro (Exactpro Systems Limited) + * Copyright 2021-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -117,11 +117,14 @@ public AbstractMessageIteratorProvider(String requestInfo, MessageFilter filter, } //TODO refactor this method to assigns firstPage outside the method - protected FilterForGreater createLeftBoundFilter(MessageFilter filter) throws CradleStorageException - { + protected FilterForGreater createLeftBoundFilter(MessageFilter filter) throws CradleStorageException { FilterForGreater result = filter.getTimestampFrom(); firstPage = FilterUtils.findFirstPage(filter.getPageId(), result, book); - Instant leftBoundFromPage = firstPage.getStarted(); + + if (result == null && firstPage == null) + return null; + + Instant leftBoundFromPage = firstPage == null ? Instant.MIN : firstPage.getStarted(); if (result == null || (filter.getPageId() != null && leftBoundFromPage.isAfter(result.getValue()))) return FilterForGreater.forGreaterOrEquals(leftBoundFromPage); @@ -132,8 +135,7 @@ protected FilterForGreater createLeftBoundFilter(MessageFilter filter) filter.getDirection().getLabel(), leftBoundLocalDate.toLocalDate(), leftBoundLocalDate.toLocalTime()); - if (nearestBatchTime != null) - { + if (nearestBatchTime != null) { Instant nearestBatchInstant = TimeUtils.toInstant(leftBoundLocalDate.toLocalDate(), nearestBatchTime); if (nearestBatchInstant.isBefore(result.getValue())) result = FilterForGreater.forGreaterOrEquals(nearestBatchInstant); @@ -175,11 +177,10 @@ private LocalTime getNearestBatchTime(PageInfo page, String sessionAlias, String } //TODO refactor this method to assign last page outside of this method. - protected FilterForLess createRightBoundFilter(MessageFilter filter) - { + protected FilterForLess createRightBoundFilter(MessageFilter filter) { FilterForLess result = filter.getTimestampTo(); lastPage = FilterUtils.findLastPage(filter.getPageId(), result, book); - Instant endOfPage = lastPage.getEnded() == null ? Instant.now() : lastPage.getEnded(); + Instant endOfPage = lastPage == null || lastPage.getEnded() == null ? Instant.now() : lastPage.getEnded(); return FilterForLess.forLessOrEquals(result == null || endOfPage.isBefore(result.getValue()) ? endOfPage : result.getValue()); } @@ -240,22 +241,22 @@ protected CassandraStoredMessageFilter createNextFilter(CassandraStoredMessageFi filter.getOrder()); } - protected boolean performNextIteratorChecks () { + protected boolean interruptIteratorChecks () { if (cassandraFilter == null) { - return false; + return true; } if (takeWhileIterator != null && takeWhileIterator.isHalted()) { logger.debug("Iterator was interrupted because iterator condition was not met"); - return false; + return true; } if (limit > 0 && returned.get() >= limit) { logger.debug("Filtering interrupted because limit for records to return ({}) is reached ({})", limit, returned); - return false; + return true; } - return true; + return false; } protected Iterator getBatchedIterator (MappedAsyncPagingIterable resultSet) { diff --git a/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/messages/MessageBatchesIteratorProvider.java b/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/messages/MessageBatchesIteratorProvider.java index 2ce9d4610..4697df9cc 100644 --- a/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/messages/MessageBatchesIteratorProvider.java +++ b/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/messages/MessageBatchesIteratorProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2023 Exactpro (Exactpro Systems Limited) + * Copyright 2021-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,15 +38,14 @@ public class MessageBatchesIteratorProvider extends AbstractMessageIteratorProvi public MessageBatchesIteratorProvider(String requestInfo, MessageFilter filter, CassandraOperators operators, BookInfo book, ExecutorService composingService, SelectQueryExecutor selectQueryExecutor, - Function readAttrs) throws CradleStorageException - { + Function readAttrs) throws CradleStorageException { super(requestInfo, filter, operators, book, composingService, selectQueryExecutor, readAttrs); } @Override public CompletableFuture> nextIterator() { - if (!performNextIteratorChecks()) { + if (interruptIteratorChecks()) { return CompletableFuture.completedFuture(null); } @@ -55,4 +54,4 @@ public CompletableFuture> nextIterator() { .thenApplyAsync(this::getBatchedIterator, composingService) .thenApply(it -> limit > 0 ? new LimitedIterator<>(it, limit) : it); } -} +} \ No newline at end of file diff --git a/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/messages/MessagesIteratorProvider.java b/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/messages/MessagesIteratorProvider.java index c9370a980..3e378943f 100644 --- a/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/messages/MessagesIteratorProvider.java +++ b/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/messages/MessagesIteratorProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2023 Exactpro (Exactpro Systems Limited) + * Copyright 2021-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,15 +36,13 @@ public class MessagesIteratorProvider extends AbstractMessageIteratorProvider readAttrs) throws CradleStorageException - { + Function readAttrs) throws CradleStorageException { super(requestInfo, filter, operators, book, composingService, selectQueryExecutor, readAttrs); } @Override - public CompletableFuture> nextIterator() - { - if (!performNextIteratorChecks()) { + public CompletableFuture> nextIterator() { + if (interruptIteratorChecks()) { return CompletableFuture.completedFuture(null); } @@ -53,4 +51,4 @@ public CompletableFuture> nextIterator() .thenApplyAsync(this::getBatchedIterator, composingService) .thenApplyAsync(it -> new FilteredMessageIterator(it, filter, limit, returned), composingService); } -} +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 60a79290a..2d0fef2e0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ -release_version=5.1.4 +release_version=5.1.5 description='Cradle API' vcs_url=https://github.com/th2-net/cradleapi