Improved: Fix or Silence various warnings
(OFBIZ-10701)
In order to detect potential issues early, the linting compiler option should be
used by default and disabled with {{./gradlew -PXlint:none build}}.
Additionally it is important to reduce the number of warnings otherwise new
warnings will remain unnoticed.
The warning related to the com.googlecode.concurrentlinkedhashmap dependency
should resolves itself once we handle upgrade to Caffeine like proposed in
OFBIZ-6747.
Thanks: Mathieu Lirzin
git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1848673 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -281,6 +281,7 @@ public class GenericEntity implements Map<String, Object>, LocalizedMap<Object>,
|
||||
*
|
||||
* @deprecated Use hasChanged()
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isModified() {
|
||||
return this.hasChanged();
|
||||
}
|
||||
|
||||
+5
-14
@@ -22,6 +22,7 @@ package org.apache.ofbiz.entity.condition;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.ofbiz.base.util.Debug;
|
||||
import org.apache.ofbiz.base.util.PatternFactory;
|
||||
@@ -242,21 +243,11 @@ public abstract class EntityComparisonOperator<L, R> extends EntityOperator<L, R
|
||||
return true;
|
||||
}
|
||||
|
||||
public static final <L,R> boolean compareIn(L lhs, R rhs) {
|
||||
if (lhs == null) {
|
||||
if (rhs != null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else if (rhs instanceof Collection<?>) {
|
||||
if (((Collection<?>) rhs).contains(lhs)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} else if (lhs.equals(rhs)) {
|
||||
return true;
|
||||
public static final <L, R extends L> boolean compareIn(L lhs, R rhs) {
|
||||
if (rhs instanceof Collection && lhs != null) {
|
||||
return (((Collection<?>) rhs).contains(lhs));
|
||||
} else {
|
||||
return false;
|
||||
return Objects.equals(lhs, rhs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,10 +56,12 @@ public abstract class EntityCondition extends EntityConditionBase implements IsE
|
||||
return new EntityExpr(lhs, operator, rhs);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <T extends EntityCondition> EntityConditionList<T> makeCondition(EntityJoinOperator operator, T... conditionList) {
|
||||
return new EntityConditionList<>(Arrays.<T>asList(conditionList), operator);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <T extends EntityCondition> EntityConditionList<T> makeCondition(T... conditionList) {
|
||||
return new EntityConditionList<>(Arrays.<T>asList(conditionList), EntityOperator.AND);
|
||||
}
|
||||
|
||||
+2
-15
@@ -25,7 +25,6 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.ofbiz.base.util.Debug;
|
||||
import org.apache.ofbiz.base.util.UtilGenerics;
|
||||
import org.apache.ofbiz.entity.Delegator;
|
||||
import org.apache.ofbiz.entity.GenericModelException;
|
||||
@@ -45,18 +44,6 @@ public class EntityConditionBuilder extends BuilderSupport {
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
public Object asType(Class clz) {
|
||||
Debug.logInfo("asType(%s): %s", module, clz, condition);
|
||||
if (clz == EntityCondition.class) {
|
||||
return condition;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityCondition build() {
|
||||
return condition;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return condition.isEmpty();
|
||||
}
|
||||
@@ -106,7 +93,7 @@ public class EntityConditionBuilder extends BuilderSupport {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object createNode(Object methodName, Map mapArg) {
|
||||
protected Object createNode(Object methodName, @SuppressWarnings("rawtypes") Map mapArg) {
|
||||
Map<String, Object> fieldValueMap = UtilGenerics.checkMap(mapArg);
|
||||
String operatorName = ((String)methodName).toLowerCase(Locale.getDefault());
|
||||
EntityComparisonOperator<String, Object> operator = EntityOperator.lookupComparison(operatorName);
|
||||
@@ -121,7 +108,7 @@ public class EntityConditionBuilder extends BuilderSupport {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object createNode(Object methodName, Map mapArg, Object objArg) {
|
||||
protected Object createNode(Object methodName, @SuppressWarnings("rawtypes") Map mapArg, Object objArg) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ public final class EntityFieldMap extends EntityConditionListBase<EntityExpr> {
|
||||
return list;
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public <V> EntityFieldMap(EntityComparisonOperator<?,?> compOp, EntityJoinOperator joinOp, V... keysValues) {
|
||||
this(EntityUtil.makeFields(keysValues), UtilGenerics.<EntityComparisonOperator<String,V>>cast(compOp), joinOp);
|
||||
}
|
||||
|
||||
+6
-5
@@ -56,11 +56,12 @@ public class DBCPConnectionFactory implements ConnectionFactory {
|
||||
public static final String module = DBCPConnectionFactory.class.getName();
|
||||
// ManagedDataSource is useful to debug the usage of connections in the pool (must be verbose)
|
||||
// In case you don't want to be disturbed in the log (focusing on something else), it's still easy to comment out the line from DebugManagedDataSource
|
||||
protected static final ConcurrentHashMap<String, DebugManagedDataSource> dsCache = new ConcurrentHashMap<String, DebugManagedDataSource>();
|
||||
protected static final ConcurrentHashMap<String, DebugManagedDataSource<? extends Connection>> dsCache =
|
||||
new ConcurrentHashMap<>();
|
||||
|
||||
public Connection getConnection(GenericHelperInfo helperInfo, JdbcElement abstractJdbc) throws SQLException, GenericEntityException {
|
||||
String cacheKey = helperInfo.getHelperFullName();
|
||||
DebugManagedDataSource mds = dsCache.get(cacheKey);
|
||||
DebugManagedDataSource<? extends Connection> mds = dsCache.get(cacheKey);
|
||||
if (mds != null) {
|
||||
return TransactionUtil.getCursorConnection(helperInfo, mds.getConnection());
|
||||
}
|
||||
@@ -127,7 +128,7 @@ public class DBCPConnectionFactory implements ConnectionFactory {
|
||||
}
|
||||
|
||||
// configure the pool settings
|
||||
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
|
||||
GenericObjectPoolConfig<PoolableConnection> poolConfig = new GenericObjectPoolConfig<>();
|
||||
poolConfig.setMaxTotal(maxSize);
|
||||
// settings for idle connections
|
||||
poolConfig.setMaxIdle(maxIdle);
|
||||
@@ -148,7 +149,7 @@ public class DBCPConnectionFactory implements ConnectionFactory {
|
||||
GenericObjectPool<PoolableConnection> pool = new GenericObjectPool<PoolableConnection>(factory, poolConfig);
|
||||
factory.setPool(pool);
|
||||
|
||||
mds = new DebugManagedDataSource(pool, xacf.getTransactionRegistry());
|
||||
mds = new DebugManagedDataSource<>(pool, xacf.getTransactionRegistry());
|
||||
mds.setAccessToUnderlyingConnectionAllowed(true);
|
||||
|
||||
// cache the pool
|
||||
@@ -165,7 +166,7 @@ public class DBCPConnectionFactory implements ConnectionFactory {
|
||||
|
||||
public static Map<String, Object> getDataSourceInfo(String helperName) {
|
||||
Map<String, Object> dataSourceInfo = new HashMap<String, Object>();
|
||||
DebugManagedDataSource mds = dsCache.get(helperName);
|
||||
DebugManagedDataSource<? extends Connection> mds = dsCache.get(helperName);
|
||||
if (mds != null) {
|
||||
dataSourceInfo = mds.getInfo();
|
||||
}
|
||||
|
||||
+18
-4
@@ -30,11 +30,11 @@ import org.apache.commons.pool2.ObjectPool;
|
||||
import org.apache.commons.pool2.impl.GenericObjectPool;
|
||||
import org.apache.ofbiz.base.util.Debug;
|
||||
|
||||
public class DebugManagedDataSource extends ManagedDataSource {
|
||||
public class DebugManagedDataSource<C extends Connection> extends ManagedDataSource<C> {
|
||||
|
||||
public static final String module = DebugManagedDataSource.class.getName();
|
||||
|
||||
public DebugManagedDataSource(ObjectPool pool, TransactionRegistry transactionRegistry) {
|
||||
public DebugManagedDataSource(ObjectPool<C> pool, TransactionRegistry transactionRegistry) {
|
||||
super(pool, transactionRegistry);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class DebugManagedDataSource extends ManagedDataSource {
|
||||
public Connection getConnection() throws SQLException {
|
||||
if (Debug.verboseOn()) {
|
||||
if (super.getPool() instanceof GenericObjectPool) {
|
||||
GenericObjectPool objectPool = (GenericObjectPool)super.getPool();
|
||||
GenericObjectPool<?> objectPool = (GenericObjectPool<?>)super.getPool();
|
||||
Debug.logVerbose("Borrowing a connection from the pool; used/idle/total: " + objectPool.getNumActive() + "/" + objectPool.getNumIdle() + "/" + (objectPool.getNumActive() + objectPool.getNumIdle()) + "; min idle/max idle/max total: " + objectPool.getMinIdle() + "/" + objectPool.getMaxIdle() + "/" + objectPool.getMaxTotal(), module);
|
||||
} else {
|
||||
if (Debug.verboseOn()) Debug.logVerbose("Borrowing a connection from the pool; used/idle/total: " + super.getPool().getNumActive() + "/" + super.getPool().getNumIdle() + "/" + (super.getPool().getNumActive() + super.getPool().getNumIdle()), module);
|
||||
@@ -57,7 +57,7 @@ public class DebugManagedDataSource extends ManagedDataSource {
|
||||
dataSourceInfo.put("poolNumIdle", super.getPool().getNumIdle());
|
||||
dataSourceInfo.put("poolNumTotal", (super.getPool().getNumIdle() + super.getPool().getNumActive()));
|
||||
if (super.getPool() instanceof GenericObjectPool) {
|
||||
GenericObjectPool objectPool = (GenericObjectPool)super.getPool();
|
||||
GenericObjectPool<?> objectPool = (GenericObjectPool<?>)super.getPool();
|
||||
dataSourceInfo.put("poolMaxActive", objectPool.getMaxTotal());
|
||||
dataSourceInfo.put("poolMaxIdle", objectPool.getMaxIdle());
|
||||
dataSourceInfo.put("poolMaxWait", objectPool.getMaxWaitMillis());
|
||||
@@ -67,4 +67,18 @@ public class DebugManagedDataSource extends ManagedDataSource {
|
||||
return dataSourceInfo;
|
||||
}
|
||||
|
||||
// Ensures that the close() method does not throw an InterruptedException
|
||||
// to conform to the AutoCloseable interface.
|
||||
// This is fixing what should be down in org.apache.commons.dbcp2.PoolingDataSource.
|
||||
@Override
|
||||
public void close() throws SQLException, RuntimeException {
|
||||
try {
|
||||
super.close();
|
||||
} catch (SQLException | RuntimeException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
Debug.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -798,7 +798,7 @@ public class DatabaseUtil {
|
||||
protected Detection(String name, boolean required, String methodName, Object... params) throws NoSuchMethodException {
|
||||
this.name = name;
|
||||
this.required = required;
|
||||
Class[] paramTypes = new Class[params.length];
|
||||
Class<?>[] paramTypes = new Class<?>[params.length];
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
Class<?> paramType = params[i].getClass();
|
||||
if (paramType == Integer.class) {
|
||||
|
||||
@@ -58,6 +58,7 @@ import org.w3c.dom.Element;
|
||||
* An object that models the <code><entity></code> element.
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ModelEntity implements Comparable<ModelEntity>, Serializable {
|
||||
|
||||
public static final String module = ModelEntity.class.getName();
|
||||
|
||||
@@ -139,8 +139,6 @@ public class EntityTestSuite extends EntityTestCase {
|
||||
testValue.addObserver(observer);
|
||||
testValue.put("description", "New Testing Type #Update-1");
|
||||
assertEquals("Observer called with original GenericValue field name", "description", observer.arg);
|
||||
observer.observable = null;
|
||||
observer.arg = null;
|
||||
GenericValue clonedValue = (GenericValue) testValue.clone();
|
||||
clonedValue.put("description", "New Testing Type #Update-1");
|
||||
assertTrue("Cloned Observable has changed", clonedValue.hasChanged());
|
||||
@@ -1249,7 +1247,7 @@ public class EntityTestSuite extends EntityTestCase {
|
||||
try {
|
||||
transactionStarted = TransactionUtil.begin();
|
||||
for (int i = 1; i <= numberOfQueries; i++) {
|
||||
List rows = EntityQuery.use(delegator).from("SequenceValueItem").queryList();
|
||||
List<GenericValue> rows = EntityQuery.use(delegator).from("SequenceValueItem").queryList();
|
||||
totalNumberOfRows = totalNumberOfRows + rows.size();
|
||||
}
|
||||
TransactionUtil.commit(transactionStarted);
|
||||
@@ -1270,7 +1268,7 @@ public class EntityTestSuite extends EntityTestCase {
|
||||
try {
|
||||
for (int i = 1; i <= numberOfQueries; i++) {
|
||||
transactionStarted = TransactionUtil.begin();
|
||||
List rows = EntityQuery.use(delegator).from("SequenceValueItem").queryList();
|
||||
List<GenericValue> rows = EntityQuery.use(delegator).from("SequenceValueItem").queryList();
|
||||
totalNumberOfRows = totalNumberOfRows + rows.size();
|
||||
TransactionUtil.commit(transactionStarted);
|
||||
}
|
||||
@@ -1288,12 +1286,10 @@ public class EntityTestSuite extends EntityTestCase {
|
||||
}
|
||||
|
||||
private final class TestObserver implements Observer {
|
||||
private Observable observable;
|
||||
private Object arg;
|
||||
|
||||
@Override
|
||||
public void update(Observable observable, Object arg) {
|
||||
this.observable = observable;
|
||||
this.arg = arg;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-13
@@ -47,7 +47,6 @@ import javax.transaction.xa.Xid;
|
||||
import org.apache.commons.collections4.map.ListOrderedMap;
|
||||
import org.apache.ofbiz.base.util.Debug;
|
||||
import org.apache.ofbiz.base.util.UtilDateTime;
|
||||
import org.apache.ofbiz.base.util.UtilGenerics;
|
||||
import org.apache.ofbiz.base.util.UtilValidate;
|
||||
import org.apache.ofbiz.entity.GenericEntityConfException;
|
||||
import org.apache.ofbiz.entity.GenericEntityException;
|
||||
@@ -780,10 +779,6 @@ public final class TransactionUtil implements Status {
|
||||
public void logError(String message) {
|
||||
Debug.logError(this.getCauseThrowable(), (message == null ? "" : message) + this.getCauseMessage(), module);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return (UtilValidate.isEmpty(this.getCauseMessage()) && this.getCauseThrowable() == null);
|
||||
}
|
||||
}
|
||||
|
||||
private static void pushSetRollbackOnlyCauseSave(RollbackOnlyCause e) {
|
||||
@@ -841,12 +836,8 @@ public final class TransactionUtil implements Status {
|
||||
/**
|
||||
* Maintain the suspended transactions together with their timestamps
|
||||
*/
|
||||
private static ThreadLocal<Map<Transaction, Timestamp>> suspendedTxStartStamps = new ThreadLocal<Map<Transaction, Timestamp>>() {
|
||||
@Override
|
||||
public Map<Transaction, Timestamp> initialValue() {
|
||||
return UtilGenerics.checkMap(new ListOrderedMap<>());
|
||||
}
|
||||
};
|
||||
private static ThreadLocal<ListOrderedMap<Transaction, Timestamp>> suspendedTxStartStamps =
|
||||
ThreadLocal.withInitial(ListOrderedMap::new);
|
||||
|
||||
/**
|
||||
* Put the stamp to remember later
|
||||
@@ -891,9 +882,9 @@ public final class TransactionUtil implements Status {
|
||||
* Remove the stamp from stack (when resuming)
|
||||
*/
|
||||
private static void popTransactionStartStamp() {
|
||||
ListOrderedMap map = (ListOrderedMap) suspendedTxStartStamps.get();
|
||||
ListOrderedMap<Transaction, Timestamp> map = suspendedTxStartStamps.get();
|
||||
if (map.size() > 0) {
|
||||
transactionStartStamp.set((Timestamp) map.remove(map.lastKey()));
|
||||
transactionStartStamp.set(map.remove(map.lastKey()));
|
||||
} else {
|
||||
Debug.logError("Error in transaction handling - no saved start stamp found - using NOW.", module);
|
||||
transactionStartStamp.set(UtilDateTime.nowTimestamp());
|
||||
|
||||
@@ -481,7 +481,8 @@ public class EntityQuery {
|
||||
if (whereEntityCondition == null && fieldMap != null) {
|
||||
if (this.searchPkOnly) {
|
||||
//Resolve if the map contains a sub map parameters, use a containsKeys to avoid error when a GenericValue is given as map
|
||||
Map<String, Object> parameters = fieldMap.containsKey("parameters") ? (Map<String, Object>) fieldMap.get("parameters") : null;
|
||||
Map<String, Object> parameters =
|
||||
fieldMap.containsKey("parameters") ? UtilGenerics.cast(fieldMap.get("parameters")) : null;
|
||||
GenericPK pk = GenericPK.create(delegator.getModelEntity(entityName));
|
||||
pk.setPKFields(parameters);
|
||||
pk.setPKFields(fieldMap);
|
||||
|
||||
@@ -380,7 +380,8 @@ public class EntitySaxReader extends DefaultHandler {
|
||||
currentValue.setString(currentFieldName.toString(), new String(currentFieldValue));
|
||||
}
|
||||
} else {
|
||||
Debug.logWarning("Ignoring invalid field name [" + currentFieldName + "] found for the entity: " + currentValue.getEntityName() + " with value=" + currentFieldValue, module);
|
||||
Debug.logWarning("Ignoring invalid field name [" + currentFieldName + "] found for the entity: "
|
||||
+ currentValue.getEntityName() + " with value=" + currentFieldValue.toString(), module);
|
||||
}
|
||||
currentFieldValue = null;
|
||||
}
|
||||
|
||||
@@ -323,7 +323,7 @@ public final class EntityUtil {
|
||||
//force check entity label before order by
|
||||
List<T> localizedValues = new ArrayList<T>();
|
||||
for (T value : values) {
|
||||
T newValue = (T) value.clone();
|
||||
T newValue = UtilGenerics.cast(value.clone());
|
||||
for (String orderByField : orderBy) {
|
||||
if (orderByField.endsWith(" DESC")) {
|
||||
orderByField= orderByField.substring(0, orderByField.length() - 5);
|
||||
|
||||
Reference in New Issue
Block a user