This is an automated email from the ASF dual-hosted git repository. shadow pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j-audit.git
commit 4a32859e1d2f26191277b90d010fba70d70f6fed Author: Andrei Ivanov <[email protected]> AuthorDate: Tue May 28 15:49:37 2019 +0300 Fix trivial bugs reported by the IDE --- .../service/controller/CatalogController.java | 2 +- .../logging/log4j/catalog/api/Attribute.java | 2 ++ .../catalog/controller/AttributeController.java | 2 +- .../catalog/controller/CategoryController.java | 2 +- .../log4j/catalog/controller/EventController.java | 2 +- .../catalog/controller/ProductController.java | 2 +- .../log4j/catalog/git/dao/GitCatalogDao.java | 26 +++++++++++++--------- 7 files changed, 22 insertions(+), 16 deletions(-) diff --git a/log4j-audit/log4j-audit-war/src/main/java/org/apache/logging/log4j/audit/service/controller/CatalogController.java b/log4j-audit/log4j-audit-war/src/main/java/org/apache/logging/log4j/audit/service/controller/CatalogController.java index 716dc11..4af4d0d 100644 --- a/log4j-audit/log4j-audit-war/src/main/java/org/apache/logging/log4j/audit/service/controller/CatalogController.java +++ b/log4j-audit/log4j-audit-war/src/main/java/org/apache/logging/log4j/audit/service/controller/CatalogController.java @@ -454,7 +454,7 @@ public class CatalogController { private String validateSortDirection(String sortDirection) { if (sortDirection == null) { sortDirection = "ASC"; - } else if (sortDirection != "ASC" && sortDirection != "DESC") { + } else if (!sortDirection.equals("ASC") && !sortDirection.equals("DESC")) { LOGGER.warn("Invalid sort direction {}, defaulting to ascending", sortDirection); sortDirection = "ASC"; } diff --git a/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Attribute.java b/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Attribute.java index 2c8b8f8..c315bf0 100644 --- a/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Attribute.java +++ b/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Attribute.java @@ -302,6 +302,8 @@ public class Attribute implements Serializable { for (Constraint constraint : constraints) { if (!first) { sb.append(" "); + } else { + first = false; } sb.append("name=\"").append(constraint.getConstraintType().getName()).append("\""); sb.append("value=\"").append(constraint.getValue()).append("\""); diff --git a/log4j-catalog/log4j-catalog-editor/src/main/java/org/apache/logging/log4j/catalog/controller/AttributeController.java b/log4j-catalog/log4j-catalog-editor/src/main/java/org/apache/logging/log4j/catalog/controller/AttributeController.java index 5f3bfbc..2be6dfb 100644 --- a/log4j-catalog/log4j-catalog-editor/src/main/java/org/apache/logging/log4j/catalog/controller/AttributeController.java +++ b/log4j-catalog/log4j-catalog-editor/src/main/java/org/apache/logging/log4j/catalog/controller/AttributeController.java @@ -91,7 +91,7 @@ public class AttributeController { if (sorting != null) { String[] sortInfo = sorting.split(" "); sortColumn = sortInfo[0]; - if (sortInfo.length > 0) { + if (sortInfo.length > 1) { sortDirection = sortInfo[1]; } } diff --git a/log4j-catalog/log4j-catalog-editor/src/main/java/org/apache/logging/log4j/catalog/controller/CategoryController.java b/log4j-catalog/log4j-catalog-editor/src/main/java/org/apache/logging/log4j/catalog/controller/CategoryController.java index 16ef136..7a937d5 100644 --- a/log4j-catalog/log4j-catalog-editor/src/main/java/org/apache/logging/log4j/catalog/controller/CategoryController.java +++ b/log4j-catalog/log4j-catalog-editor/src/main/java/org/apache/logging/log4j/catalog/controller/CategoryController.java @@ -84,7 +84,7 @@ public class CategoryController { if (sorting != null) { String[] sortInfo = sorting.split(" "); sortColumn = sortInfo[0]; - if (sortInfo.length > 0) { + if (sortInfo.length > 1) { sortDirection = sortInfo[1]; } } diff --git a/log4j-catalog/log4j-catalog-editor/src/main/java/org/apache/logging/log4j/catalog/controller/EventController.java b/log4j-catalog/log4j-catalog-editor/src/main/java/org/apache/logging/log4j/catalog/controller/EventController.java index 89b9a94..2381200 100644 --- a/log4j-catalog/log4j-catalog-editor/src/main/java/org/apache/logging/log4j/catalog/controller/EventController.java +++ b/log4j-catalog/log4j-catalog-editor/src/main/java/org/apache/logging/log4j/catalog/controller/EventController.java @@ -87,7 +87,7 @@ public class EventController { if (sorting != null) { String[] sortInfo = sorting.split(" "); sortColumn = sortInfo[0]; - if (sortInfo.length > 0) { + if (sortInfo.length > 1) { sortDirection = sortInfo[1]; } } diff --git a/log4j-catalog/log4j-catalog-editor/src/main/java/org/apache/logging/log4j/catalog/controller/ProductController.java b/log4j-catalog/log4j-catalog-editor/src/main/java/org/apache/logging/log4j/catalog/controller/ProductController.java index f24d8a5..f8ff531 100644 --- a/log4j-catalog/log4j-catalog-editor/src/main/java/org/apache/logging/log4j/catalog/controller/ProductController.java +++ b/log4j-catalog/log4j-catalog-editor/src/main/java/org/apache/logging/log4j/catalog/controller/ProductController.java @@ -83,7 +83,7 @@ public class ProductController { if (sorting != null) { String[] sortInfo = sorting.split(" "); sortColumn = sortInfo[0]; - if (sortInfo.length > 0) { + if (sortInfo.length > 1) { sortDirection = sortInfo[1]; } } diff --git a/log4j-catalog/log4j-catalog-git/src/main/java/org/apache/logging/log4j/catalog/git/dao/GitCatalogDao.java b/log4j-catalog/log4j-catalog-git/src/main/java/org/apache/logging/log4j/catalog/git/dao/GitCatalogDao.java index 9467a1a..7d1c012 100644 --- a/log4j-catalog/log4j-catalog-git/src/main/java/org/apache/logging/log4j/catalog/git/dao/GitCatalogDao.java +++ b/log4j-catalog/log4j-catalog-git/src/main/java/org/apache/logging/log4j/catalog/git/dao/GitCatalogDao.java @@ -16,13 +16,6 @@ */ package org.apache.logging.log4j.catalog.git.dao; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneId; - import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.ObjectMapper; @@ -34,8 +27,8 @@ import org.apache.logging.log4j.catalog.api.CatalogData; import org.apache.logging.log4j.catalog.api.dao.AbstractCatalogReader; import org.apache.logging.log4j.catalog.api.dao.CatalogDao; import org.apache.logging.log4j.catalog.api.exception.CatalogModificationException; -import org.apache.logging.log4j.catalog.api.exception.CatalogReadException; import org.apache.logging.log4j.catalog.api.exception.CatalogNotFoundException; +import org.apache.logging.log4j.catalog.api.exception.CatalogReadException; import org.apache.logging.log4j.catalog.api.util.CatalogEventFilter; import org.eclipse.jgit.api.CloneCommand; import org.eclipse.jgit.api.Git; @@ -47,6 +40,13 @@ import org.eclipse.jgit.internal.storage.file.FileRepository; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.transport.CredentialsProvider; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; + public class GitCatalogDao extends AbstractCatalogReader implements CatalogDao { private static final Logger LOGGER = LogManager.getLogger(); private static final String DEFAULT_CATALOG_PATH = "src/main/resources/catalog.json"; @@ -133,8 +133,12 @@ public class GitCatalogDao extends AbstractCatalogReader implements CatalogDao { @Override public synchronized CatalogData read() { updateRepo(); - if (catalogFile == null || !catalogFile.exists() || !catalogFile.canRead()) { - throw new IllegalStateException("Catalog " + catalogFile.getAbsolutePath() + " is not readable."); + if (catalogFile == null) { + throw new CatalogNotFoundException(); + } + + if (!catalogFile.exists() || !catalogFile.canRead()) { + throw new CatalogReadException("Catalog " + catalogFile.getAbsolutePath() + " is not readable."); } try { @@ -149,7 +153,7 @@ public class GitCatalogDao extends AbstractCatalogReader implements CatalogDao { public void write(CatalogData data) { File localRepoFile = new File(localRepoPath); if (!localRepoFile.exists() || !localRepoFile.canWrite()) { - throw new IllegalStateException("Catalog is not writable."); + throw new CatalogModificationException("Catalog is not writable: " + localRepoFile.getAbsolutePath()); } FileWriter writer = null;
