Improved: Fixing defects reported by FindBugs, package
org.apache.ofbiz.entity.util. (OFBIZ-9720) Thanks Julian Leichert for reporting and providing the patch. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1817562 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -33,6 +33,7 @@ import org.apache.ofbiz.base.crypto.HashCrypt;
|
||||
import org.apache.ofbiz.base.util.Debug;
|
||||
import org.apache.ofbiz.base.util.GeneralException;
|
||||
import org.apache.ofbiz.base.util.StringUtil;
|
||||
import org.apache.ofbiz.base.util.UtilIO;
|
||||
import org.apache.ofbiz.base.util.UtilObject;
|
||||
import org.apache.ofbiz.base.util.UtilValidate;
|
||||
import org.apache.ofbiz.entity.Delegator;
|
||||
@@ -51,9 +52,9 @@ public final class EntityCrypto {
|
||||
|
||||
public static final String module = EntityCrypto.class.getName();
|
||||
|
||||
protected final Delegator delegator;
|
||||
protected final ConcurrentMap<String, byte[]> keyMap = new ConcurrentHashMap<String, byte[]>();
|
||||
protected final StorageHandler[] handlers;
|
||||
private final Delegator delegator;
|
||||
private final ConcurrentMap<String, byte[]> keyMap = new ConcurrentHashMap<String, byte[]>();
|
||||
private final StorageHandler[] handlers;
|
||||
|
||||
public EntityCrypto(Delegator delegator, String kekText) throws EntityCryptoException {
|
||||
this.delegator = delegator;
|
||||
@@ -379,7 +380,7 @@ public final class EntityCrypto {
|
||||
|
||||
@Override
|
||||
protected String getHashedKeyName(String originalKeyName) {
|
||||
return HashCrypt.digestHash64("SHA", originalKeyName.getBytes());
|
||||
return HashCrypt.digestHash64("SHA", originalKeyName.getBytes(UtilIO.getUtf8()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,10 +19,12 @@
|
||||
package org.apache.ofbiz.entity.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.apache.ofbiz.base.component.ComponentConfig;
|
||||
@@ -48,6 +50,7 @@ import org.apache.ofbiz.entity.model.ModelReader;
|
||||
import org.apache.ofbiz.entity.model.ModelUtil;
|
||||
import org.apache.ofbiz.entity.model.ModelViewEntity;
|
||||
import org.w3c.dom.Element;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* Some utility routines for loading seed data.
|
||||
@@ -105,7 +108,7 @@ public class EntityDataLoader {
|
||||
throw new IllegalArgumentException("Reader name list does not contain String(s) or Element(s)");
|
||||
}
|
||||
readerName = readerName.trim();
|
||||
|
||||
|
||||
// ignore the "tenant" reader if multitenant is disabled
|
||||
if ("tenant".equals(readerName) && !EntityUtil.isMultiTenantEnabled()) {
|
||||
continue;
|
||||
@@ -160,14 +163,16 @@ public class EntityDataLoader {
|
||||
if (UtilValidate.isNotEmpty(paths)) {
|
||||
StringTokenizer tokenizer = new StringTokenizer(paths, ";");
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
String path = tokenizer.nextToken().toLowerCase();
|
||||
String path = tokenizer.nextToken().toLowerCase(Locale.getDefault());
|
||||
File loadDir = new File(path);
|
||||
if (loadDir.exists() && loadDir.isDirectory()) {
|
||||
File[] files = loadDir.listFiles();
|
||||
List<File> tempFileList = new LinkedList<File>();
|
||||
for (File file: files) {
|
||||
if (file.getName().toLowerCase().endsWith(".xml")) {
|
||||
tempFileList.add(file);
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
if (file.getName().toLowerCase(Locale.getDefault()).endsWith(".xml")) {
|
||||
tempFileList.add(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
Collections.sort(tempFileList);
|
||||
@@ -214,7 +219,7 @@ public class EntityDataLoader {
|
||||
if ("tenant".equals(readerName) && "N".equals(UtilProperties.getPropertyValue("general", "multitenant"))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
readerNames.add(readerName);
|
||||
}
|
||||
return getUrlByComponentList(helperName, components, readerNames);
|
||||
@@ -261,7 +266,7 @@ public class EntityDataLoader {
|
||||
reader.setMaintainTxStamps(maintainTxs);
|
||||
reader.setContinueOnFail(continueOnFail);
|
||||
rowsChanged += reader.parse(dataUrl);
|
||||
} catch (Exception e) {
|
||||
} catch (IOException | SAXException e) {
|
||||
String xmlError = "[loadData]: Error loading XML Resource \"" + dataUrl.toExternalForm() + "\"; Error was: " + e.getMessage();
|
||||
errorMessages.add(xmlError);
|
||||
if (continueOnFail) {
|
||||
|
||||
@@ -459,7 +459,7 @@ public class EntityQuery {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private EntityFindOptions makeEntityFindOptions() {
|
||||
EntityFindOptions findOptions = new EntityFindOptions();
|
||||
if (resultSetType != null) {
|
||||
|
||||
@@ -18,11 +18,11 @@
|
||||
*******************************************************************************/
|
||||
package org.apache.ofbiz.entity.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.StringWriter;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
@@ -40,6 +40,7 @@ import javax.xml.parsers.SAXParserFactory;
|
||||
import org.apache.ofbiz.base.location.FlexibleLocation;
|
||||
import org.apache.ofbiz.base.util.Base64;
|
||||
import org.apache.ofbiz.base.util.Debug;
|
||||
import org.apache.ofbiz.base.util.UtilIO;
|
||||
import org.apache.ofbiz.base.util.UtilMisc;
|
||||
import org.apache.ofbiz.base.util.UtilValidate;
|
||||
import org.apache.ofbiz.base.util.UtilXml;
|
||||
@@ -239,7 +240,7 @@ public class EntitySaxReader extends DefaultHandler {
|
||||
valuesToDelete.clear();
|
||||
}
|
||||
TransactionUtil.commit(beganTransaction);
|
||||
} catch (Exception e) {
|
||||
} catch (GenericEntityException | IOException | IllegalArgumentException | SAXException e) {
|
||||
String errMsg = "An error occurred saving the data, rolling back transaction (" + beganTransaction + ")";
|
||||
Debug.logError(e, errMsg, module);
|
||||
TransactionUtil.rollback(beganTransaction, errMsg, e);
|
||||
@@ -318,7 +319,7 @@ public class EntitySaxReader extends DefaultHandler {
|
||||
throw new SAXException("Could not find transform template with resource path: " + templatePath);
|
||||
} else {
|
||||
try {
|
||||
Reader templateReader = new InputStreamReader(templateUrl.openStream());
|
||||
BufferedReader templateReader = new BufferedReader(new InputStreamReader(templateUrl.openStream(),UtilIO.getUtf8()));
|
||||
|
||||
StringWriter outWriter = new StringWriter();
|
||||
Configuration config = FreeMarkerWorker.newConfiguration();
|
||||
|
||||
@@ -222,7 +222,7 @@ public class SequenceUtil {
|
||||
|
||||
}
|
||||
}
|
||||
// 2 - select the record (now locked) to get the curSeqId
|
||||
// 2 - select the record (now locked) to get thec curSeqId
|
||||
rs = stmt.executeQuery(selectSequenceStatement);
|
||||
boolean sequenceFound = rs.next();
|
||||
if (sequenceFound) {
|
||||
@@ -250,12 +250,12 @@ public class SequenceUtil {
|
||||
Debug.logWarning(sqle, "Error closing statement in sequence util", module);
|
||||
}
|
||||
try {
|
||||
if (connection != null) connection.close();
|
||||
connection.close();
|
||||
} catch (SQLException sqle) {
|
||||
Debug.logWarning(sqle, "Error closing connection in sequence util", module);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (SQLException | GenericEntityException e) {
|
||||
// reset the sequence fields and return (note: it would be better to throw an exception)
|
||||
curSeqId = 0;
|
||||
maxSeqId = 0;
|
||||
|
||||
Reference in New Issue
Block a user