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 b4da24faa2e7a498ec690009c606ae3234342148
Author: Andrei Ivanov <[email protected]>
AuthorDate: Tue May 28 15:51:47 2019 +0300

    Fix trivial warnings reported by the IDE
---
 .../logging/log4j/audit/generator/ClassGenerator.java     | 15 +++++++--------
 .../org/apache/logging/log4j/audit/util/NamingUtils.java  |  4 ++--
 .../log4j/audit/service/catalog/AuditCatalogManager.java  |  1 -
 .../org/apache/logging/log4j/catalog/api/Constraint.java  |  5 ++---
 .../log4j/catalog/api/dao/ClassPathCatalogReader.java     | 11 +++++------
 .../logging/log4j/catalog/git/dao/GitCatalogDao.java      |  6 +-----
 .../log4j/catalog/jpa/converter/EventConverter.java       |  8 +++-----
 7 files changed, 20 insertions(+), 30 deletions(-)

diff --git 
a/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/generator/ClassGenerator.java
 
b/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/generator/ClassGenerator.java
index 6bcebfc..9c535e8 100644
--- 
a/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/generator/ClassGenerator.java
+++ 
b/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/generator/ClassGenerator.java
@@ -217,10 +217,9 @@ public final class ClassGenerator {
             LOGGER.info(fullPath);
         }
         File file = new File(fullPath);
-        DataOutputStream out = new DataOutputStream(openOutputStream(file));
-        out.writeBytes(getClassContents());
-        out.close();
-
+        try (DataOutputStream out = new 
DataOutputStream(openOutputStream(file))) {
+            out.writeBytes(getClassContents());
+        }
     }
 
     public String getClassContents() throws Exception {
@@ -235,7 +234,7 @@ public final class ClassGenerator {
 
         StringBuilder sb = new StringBuilder();
         sb.append("package ").append(getPackageName()).append(";\n\n");
-        if (getImports() != null) {
+        if (!getImports().isEmpty()) {
             List<String> list = new ArrayList<>(getImports());
             Collections.sort(list);
             for (String element : list) {
@@ -270,7 +269,7 @@ public final class ClassGenerator {
         if (getParentClassName() != null && getParentClassName().length() > 0) 
{
             sb.append(" extends ").append(getParentClassName());
         }
-        if (getImplements() != null && getImplements().size() > 0) {
+        if (!getImplements().isEmpty()) {
             sb.append(" implements ");
             boolean first = true;
             for (String element : getImplements()) {
@@ -282,14 +281,14 @@ public final class ClassGenerator {
             }
         }
         sb.append(" {\n\n");
-        if (localVariables != null) {
+        if (!localVariables.isEmpty()) {
             Collections.sort(localVariables);
             for (VariableDefinition element : localVariables) {
                 sb.append(element).append("\n");
             }
         }
 
-        if (constructors != null) {
+        if (!constructors.isEmpty()) {
             Collections.sort(constructors);
             for (ConstructorDefinition element : constructors) {
                 sb.append(element).append("\n\n");
diff --git 
a/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/util/NamingUtils.java
 
b/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/util/NamingUtils.java
index 6fb5063..f736d3a 100644
--- 
a/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/util/NamingUtils.java
+++ 
b/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/util/NamingUtils.java
@@ -22,11 +22,11 @@ public final class NamingUtils {
     }
 
     public static String getPackageName(String className) {
-        return className.substring(0, className.lastIndexOf("."));
+        return className.substring(0, className.lastIndexOf('.'));
     }
 
     public static String getSimpleName(String className) {
-        return className.substring(className.lastIndexOf(".") + 1);
+        return className.substring(className.lastIndexOf('.') + 1);
     }
 
     public static String getMethodShortName(String name) {
diff --git 
a/log4j-audit/log4j-audit-war/src/main/java/org/apache/logging/log4j/audit/service/catalog/AuditCatalogManager.java
 
b/log4j-audit/log4j-audit-war/src/main/java/org/apache/logging/log4j/audit/service/catalog/AuditCatalogManager.java
index 3b8d340..a0c1ac5 100644
--- 
a/log4j-audit/log4j-audit-war/src/main/java/org/apache/logging/log4j/audit/service/catalog/AuditCatalogManager.java
+++ 
b/log4j-audit/log4j-audit-war/src/main/java/org/apache/logging/log4j/audit/service/catalog/AuditCatalogManager.java
@@ -130,7 +130,6 @@ public class AuditCatalogManager extends CatalogManagerImpl 
implements AuditMana
             attributeModels.add(model);
             attributeMap.put(attribute.getName(), attribute);
         }
-        
attributeModels.stream().filter(m->!attributeMap.containsKey(m.getName()));
         for (AttributeModel attributeModel : attributeModels) {
             if (!attributeMap.containsKey(attributeModel.getName())) {
                 attributeService.deleteAttribute(attributeModel.getId());
diff --git 
a/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Constraint.java
 
b/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Constraint.java
index 775dcae..0ee7a19 100644
--- 
a/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Constraint.java
+++ 
b/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/Constraint.java
@@ -16,10 +16,9 @@
  */
 package org.apache.logging.log4j.catalog.api;
 
-import java.io.Serializable;
-
 import com.fasterxml.jackson.annotation.JsonIgnore;
-import org.apache.logging.log4j.catalog.api.ConstraintType;
+
+import java.io.Serializable;
 
 /**
  *
diff --git 
a/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/dao/ClassPathCatalogReader.java
 
b/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/dao/ClassPathCatalogReader.java
index 4959302..1381974 100644
--- 
a/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/dao/ClassPathCatalogReader.java
+++ 
b/log4j-catalog/log4j-catalog-api/src/main/java/org/apache/logging/log4j/catalog/api/dao/ClassPathCatalogReader.java
@@ -52,15 +52,14 @@ public class ClassPathCatalogReader extends 
AbstractCatalogReader {
         String catalogFile = attributes != null ?
             attributes.getOrDefault(CATALOG_ATTRIBUTE_NAME, 
DEFAULT_CATALOG_FILE) : DEFAULT_CATALOG_FILE;
         Collection<URL> catalogs = LoaderUtil.findResources(catalogFile);
-        URL catalogURL;
-        if (catalogs.size() == 0) {
+        if (catalogs.isEmpty()) {
             LOGGER.error("No catalog named {} could be found on the class 
path", catalogFile);
             throw new FileNotFoundException("No catalog named " + catalogFile 
+ " could be found");
-        } else if (catalogs.size() > 1) {
-            catalogURL = catalogs.stream().findFirst().get();
+        }
+
+        URL catalogURL = catalogs.iterator().next();
+        if (catalogs.size() > 1) {
             LOGGER.warn("Multiple catalogs named {} were found. Using {}", 
catalogFile, catalogURL.toString());
-        } else {
-            catalogURL = catalogs.stream().findFirst().get();
         }
 
         catalog = readCatalog(catalogURL);
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 7d1c012..bc8b9e4 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
@@ -156,15 +156,11 @@ public class GitCatalogDao extends AbstractCatalogReader 
implements CatalogDao {
             throw new CatalogModificationException("Catalog is not writable: " 
+ localRepoFile.getAbsolutePath());
         }
 
-        FileWriter writer = null;
-        try {
+        try (FileWriter writer = new FileWriter(catalogFile)){
             String text = mapper.writeValueAsString(data);
-            writer = new FileWriter(catalogFile);
             writer.write(text);
         } catch (IOException ioException) {
             throw new CatalogModificationException("Unable to write catalog 
file.", ioException);
-        } finally {
-            try { if (writer != null) writer.close(); } catch(Exception 
exception) { }
         }
 
         try (Git git = Git.open(localRepoFile)) {
diff --git 
a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/EventConverter.java
 
b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/EventConverter.java
index 60c181d..96dcc3b 100644
--- 
a/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/EventConverter.java
+++ 
b/log4j-catalog/log4j-catalog-jpa/src/main/java/org/apache/logging/log4j/catalog/jpa/converter/EventConverter.java
@@ -68,18 +68,16 @@ public class EventConverter extends 
AbstractConverter<Event, EventModel> {
         Set<EventAttributeModel> eventAttributeModels = model.getAttributes() 
!= null ? model.getAttributes() :
                 new HashSet<>();
         List<EventAttribute> eventAttributes = event.getAttributes() != null ? 
event.getAttributes() : new ArrayList<>();
-        if (event.getAttributes() != null) {
+        if (!eventAttributes.isEmpty()) {
             for (EventAttribute eventAttribute : eventAttributes) {
                 EventAttributeModel eventAttributeModel = 
model.getAttribute(eventAttribute.getName());
                 if (eventAttributeModel != null) {
-                    eventAttributeModel.setRequired(eventAttribute != null ? 
eventAttribute.isRequired() : null);
+                    
eventAttributeModel.setRequired(eventAttribute.isRequired());
                 } else {
                     Optional<AttributeModel> optional = 
getAttribute(event.getCatalogId(), eventAttribute.getName());
                     if (optional.isPresent()) {
                         eventAttributeModel = new EventAttributeModel();
-                        if (eventAttribute != null) {
-                            
eventAttributeModel.setRequired(eventAttribute.isRequired());
-                        }
+                        
eventAttributeModel.setRequired(eventAttribute.isRequired());
                         eventAttributeModel.setEvent(model);
                         eventAttributeModel.setAttribute(optional.get());
                         eventAttributeModels.add(eventAttributeModel);

Reply via email to