Skip to content

Commit

Permalink
few errors/warnings from static analysis
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Jungmann <[email protected]>
  • Loading branch information
lukasj committed Sep 17, 2021
1 parent 2972e00 commit 54abb16
Show file tree
Hide file tree
Showing 22 changed files with 134 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public class DescriptorQueryManager implements Cloneable, Serializable {
* Initialize the state of the descriptor query manager
*/
public DescriptorQueryManager() {
this.queries = new LinkedHashMap(5);
this.queries = new LinkedHashMap<>(5);
setDoesExistQuery(new DoesExistQuery());// Always has a does exist.
this.setQueryTimeout(DefaultTimeout);
this.setQueryTimeoutUnit(DefaultTimeoutUnit);
Expand Down Expand Up @@ -199,7 +199,7 @@ public synchronized void addQuery(DatabaseQuery query) {

// Add query has been synchronized for bug 3355199.
// Additionally code has been added to ensure that the same query is not added twice.
Vector queriesByName = (Vector)getQueries().get(query.getName());
List<DatabaseQuery> queriesByName = getQueries().get(query.getName());
if (queriesByName == null) {
// lazily create Vector in Hashtable.
queriesByName = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance();
Expand All @@ -209,14 +209,14 @@ public synchronized void addQuery(DatabaseQuery query) {
if (query.getArguments() != null) {
argumentTypesSize = query.getArguments().size();
}
List<String> argumentTypes = new ArrayList(argumentTypesSize);
List<String> argumentTypes = new ArrayList<>(argumentTypesSize);
for (int i = 0; i < argumentTypesSize; i++) {
argumentTypes.add(query.getArgumentTypeNames().get(i));
}

// Search for a query with the same parameters and replace it if one is found
for (int i = 0; i < queriesByName.size(); i++) {
DatabaseQuery currentQuery = (DatabaseQuery)queriesByName.get(i);
DatabaseQuery currentQuery = queriesByName.get(i);

// Here we are checking equality instead of assignability. If you look at getQuery()
// it is the other way around.
Expand Down Expand Up @@ -281,12 +281,12 @@ public Object clone() {
}

// Bug 3037701 - clone the queries
manager.setQueries(new LinkedHashMap(getQueries().size()));//bug5677655
manager.setQueries(new LinkedHashMap<>(getQueries().size()));//bug5677655
Iterator<List<DatabaseQuery>> iterator = queries.values().iterator();
while (iterator.hasNext()) {
Iterator queriesForKey = ((Vector)iterator.next()).iterator();
Iterator<DatabaseQuery> queriesForKey = iterator.next().iterator();
while (queriesForKey.hasNext()) {
DatabaseQuery initialQuery = (DatabaseQuery)queriesForKey.next();
DatabaseQuery initialQuery = queriesForKey.next();
DatabaseQuery clonedQuery = (DatabaseQuery)initialQuery.clone();
clonedQuery.setDescriptor(manager.getDescriptor());
manager.addQuery(clonedQuery);
Expand Down Expand Up @@ -329,9 +329,9 @@ public boolean containsQuery(String queryName) {
public void convertClassNamesToClasses(ClassLoader classLoader){
Iterator<List<DatabaseQuery>> queryVectors = getQueries().values().iterator();
while (queryVectors.hasNext()){
Iterator queries = ((Vector)queryVectors.next()).iterator();
Iterator<DatabaseQuery> queries = queryVectors.next().iterator();
while (queries.hasNext()){
((DatabaseQuery)queries.next()).convertClassNamesToClasses(classLoader);
queries.next().convertClassNamesToClasses(classLoader);
}
}
if (getReadObjectQuery() != null) {
Expand Down Expand Up @@ -497,7 +497,7 @@ public Map<String, List<DatabaseQuery>> getQueries() {
* @see #getQueries()
*/
public Vector getAllQueries() {
Vector allQueries = new Vector();
Vector<DatabaseQuery> allQueries = new Vector<>();
for (Iterator<List<DatabaseQuery>> vectors = getQueries().values().iterator(); vectors.hasNext();) {
allQueries.addAll(vectors.next());
}
Expand Down Expand Up @@ -575,15 +575,15 @@ public DatabaseQuery getQuery(String name, Vector arguments) {
* @see #getQuery(String)
*/
public DatabaseQuery getLocalQuery(String name, Vector arguments) {
Vector queries = (Vector)getQueries().get(name);
List<DatabaseQuery> queries = getQueries().get(name);

if (queries == null) {
return null;
}

// Short circuit the simple, most common case of only one query.
if (queries.size() == 1) {
return (DatabaseQuery)queries.firstElement();
return queries.get(0);
}

// CR#3754; Predrag; mar 19/2002;
Expand Down Expand Up @@ -1156,14 +1156,12 @@ public void removeQuery(String queryName) {
* @see #removeQuery(String)
*/
public void removeQuery(String queryName, Vector argumentTypes) {
Vector queries = (Vector)getQueries().get(queryName);
if (queries == null) {
return;
} else {
List<DatabaseQuery> queries = getQueries().get(queryName);
if (queries != null) {
DatabaseQuery query = null;
for (Enumeration enumtr = queries.elements(); enumtr.hasMoreElements();) {
query = (DatabaseQuery)enumtr.nextElement();
if (Helper.areTypesAssignable(argumentTypes, query.getArgumentTypes())) {
for (DatabaseQuery q : queries) {
if (Helper.areTypesAssignable(argumentTypes, q.getArgumentTypes())) {
query = q;
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -70,7 +70,7 @@ public interface WrapperPolicy extends Serializable {
* PUBLIC:
* Required: Wrap the object to return the implementation that the application requires.
* The object may already be wrapped in which case the object should be returned.
* @param original, the object to be wrapped
* @param original the object to be wrapped
* @param session the session to wrap the object against.
* @return java.lang.Object the wrapped object
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public interface DynamicEntity {
* @param <T>
* generic type of the property (if not provided, assume Object).
* If the property cannot be cast to the specific type, a {@link DynamicException}will be thrown.
* @param
* propertyName the name of a mapped property
* @param propertyName
* the name of a mapped property
* If the property cannot be found, a {@link DynamicException} will be thrown.
* @return
* persistent value or relationship container of the specified type
Expand All @@ -66,11 +66,11 @@ public interface DynamicEntity {
/**
* Set the persistence value for the given property to the specified value
*
* @param
* propertyName the name of a mapped property
* @param propertyName
* the name of a mapped property
* If the property cannot be found, a {@link DynamicException} will be thrown.
* @param
* value the specified object
* @param value
* the specified object
* @return
* the same DynamicEntity instance
*/
Expand All @@ -79,8 +79,8 @@ public interface DynamicEntity {
/**
* Discover if a property has a persistent value
*
* @param
* propertyName the name of a mapped property
* @param propertyName
* the name of a mapped property
* If the property cannot be found, a {@link DynamicException} will be thrown.
* @return
* true if the property has been set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,6 @@ public int appendParameterInternal(Call call, Writer writer, Object parameter) {
java.time.OffsetTime ot = (java.time.OffsetTime) dbValue;
java.sql.Timestamp ts = java.sql.Timestamp.valueOf(java.time.LocalDateTime.of(java.time.LocalDate.ofEpochDay(0), ot.toLocalTime()));
appendTimestamp(ts, writer);
} else if (dbValue instanceof java.time.LocalDate){
appendDate(java.sql.Date.valueOf((java.time.LocalDate) dbValue), writer);
} else if (dbValue instanceof java.sql.Date) {
appendDate((java.sql.Date)dbValue, writer);
} else if (dbValue == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ public Expression normalize(ExpressionNormalizer normalizer) {
for (DatabaseField field : sourceFields) {
fieldExpressions.add(left.getField(field));
}
newLeft = getBuilder().value(sourceFields);
newLeft = getBuilder().value(fieldExpressions);
} else {
newLeft = left.getField(sourceField);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2018 IBM Corporation and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -46,7 +46,8 @@ public class DMSLocalizationResource extends ListResourceBundle {
{ "disconnect_call", "Total number of disconnect calls made" },
{ "cache_hits", "The number of times that the object was found in the cache"},
{ "cache_misses", "The number of times that the object was not found in the cache" },
{ "sql_prepare", "Time spent in JDBC preparing the Statement." + "Also includes the time spent in EIS creating an Interaction associated with a connection, and creating input and output Record objects" },
{ "sql_prepare", "Time spent in JDBC preparing the Statement. " +
"Also includes the time spent in EIS creating an Interaction associated with a connection, and creating input and output Record objects" },
{ "query_prepareation", "Time to prepare the query" },
{ "sql_generation", "Time spent generating SQL. In the case of TopLink expressions, time spent converting Expression to SQL" },
{ "database_execute", "Time spent in calls to the JDBC Statement, includes time spent in calls to: close, executeUpdate, and executeQuery" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ public class LoggingLocalizationResource extends ListResourceBundle {
{ "extra_finder", "There is a finder defined on the [{0}] " + "home interface(s) but the corresponding finder [{1}{2}] " + "entry is not declared in the ejb-jar.xml." },
{ "cmp_and_cmr_field", "The ejb-jar.xml entry for [{0}] contains both a <cmp-field> and <cmr-field> entry for the attribute [{1}]. The <cmp-field> entry will be ignored." },

{ "toplink_cmp_bean_name_xml_deprecated", "Support for toplink-cmp-bean_name.xml is deprecated." + "Please refer to the documentation for the use of toplink-ejb-jar.xml" },
{ "toplink_cmp_bean_name_xml_deprecated", "Support for toplink-cmp-bean_name.xml is deprecated. " +
"Please refer to the documentation for the use of toplink-ejb-jar.xml" },

{ "drop_connection_on_error", "Warning: Dropping remote command connection to {0} on error {1}" },
{ "received_corrupt_announcement", "Warning: Discovery manager could not process service announcement due to {0} - ignoring announcement" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ private void marshalStreamOrWriter(Object object, MarshalRecord marshalRecord, A
* (such as FileWriters and OutputStreamWriters).
*/
private Writer wrapWriter(Writer writer) {
if (writer instanceof OutputStreamWriter || writer instanceof FileWriter) {
if (writer instanceof OutputStreamWriter) {
return new BufferedWriter(writer);
}
return writer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -58,7 +58,7 @@ public String getGetSettingsMethodName() {
* INTERNAL:
* Set the name of the method to be invoked to obtain an ordered list of TopLinkSetting
* objects at runtime. Only used with Sequenced objects.
* @param methodName: The name of the method.
* @param methodName The name of the method.
*/
public void setGetSettingsMethodName(String methodName) {
this.getSettingsMethodName = methodName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3858,7 +3858,7 @@ public void removeQuery(String queryName, Vector argumentTypes) {
} else {
DatabaseQuery query = null;
for (DatabaseQuery q: queries) {
if (Helper.areTypesAssignable(argumentTypes, query.getArgumentTypes())) {
if (Helper.areTypesAssignable(argumentTypes, q.getArgumentTypes())) {
query = q;
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -34,14 +34,14 @@
*/
public class CommitOrderCalculator {
protected int currentTime;
protected Vector nodes;
protected Vector<CommitOrderDependencyNode> nodes;
protected Vector orderedDescriptors;
protected AbstractSession session;

public CommitOrderCalculator(AbstractSession session) {
super();
this.currentTime = 0;
this.nodes = new Vector(1);
this.nodes = new Vector<>(1);
this.session = session;
}

Expand All @@ -61,8 +61,8 @@ public void addNodes(Vector descriptors) {
* Add to each node the dependent nodes
*/
public void calculateMappingDependencies() {
for (Enumeration e = nodes.elements(); e.hasMoreElements();) {
CommitOrderDependencyNode node = (CommitOrderDependencyNode)e.nextElement();
for (Enumeration<CommitOrderDependencyNode> e = nodes.elements(); e.hasMoreElements();) {
CommitOrderDependencyNode node = e.nextElement();
node.recordMappingDependencies();
}
}
Expand All @@ -71,8 +71,8 @@ public void calculateMappingDependencies() {
* Add to each node the dependent nodes
*/
public void calculateSpecifiedDependencies() {
for (Enumeration e = nodes.elements(); e.hasMoreElements();) {
CommitOrderDependencyNode node = (CommitOrderDependencyNode)e.nextElement();
for (Enumeration<CommitOrderDependencyNode> e = nodes.elements(); e.hasMoreElements();) {
CommitOrderDependencyNode node = e.nextElement();
node.recordSpecifiedDependencies();
}
}
Expand All @@ -88,16 +88,16 @@ public void depthFirstSearch() {
*/

//Setup
for (Enumeration e = getNodes().elements(); e.hasMoreElements();) {
CommitOrderDependencyNode node = (CommitOrderDependencyNode)e.nextElement();
for (Enumeration<CommitOrderDependencyNode> e = getNodes().elements(); e.hasMoreElements();) {
CommitOrderDependencyNode node = e.nextElement();
node.markNotVisited();
node.setPredecessor(null);
}
currentTime = 0;

//Execution
for (Enumeration e = getNodes().elements(); e.hasMoreElements();) {
CommitOrderDependencyNode node = (CommitOrderDependencyNode)e.nextElement();
for (Enumeration<CommitOrderDependencyNode> e = getNodes().elements(); e.hasMoreElements();) {
CommitOrderDependencyNode node = e.nextElement();
if (node.hasNotBeenVisited()) {
node.visit();
}
Expand Down Expand Up @@ -135,7 +135,7 @@ public int getNextTime() {
return result;
}

public Vector getNodes() {
public Vector<CommitOrderDependencyNode> getNodes() {
return nodes;
}

Expand All @@ -160,8 +160,8 @@ public Vector getOrderedDescriptors() {
}

public CommitOrderDependencyNode nodeFor(Class c) {
for (Enumeration e = nodes.elements(); e.hasMoreElements();) {
CommitOrderDependencyNode n = (CommitOrderDependencyNode)e.nextElement();
for (Enumeration<CommitOrderDependencyNode> e = nodes.elements(); e.hasMoreElements();) {
CommitOrderDependencyNode n = e.nextElement();
if (n.getDescriptor().getJavaClass() == c) {
return n;
}
Expand All @@ -170,8 +170,8 @@ public CommitOrderDependencyNode nodeFor(Class c) {
}

public CommitOrderDependencyNode nodeFor(ClassDescriptor d) {
for (Enumeration e = nodes.elements(); e.hasMoreElements();) {
CommitOrderDependencyNode n = (CommitOrderDependencyNode)e.nextElement();
for (Enumeration<CommitOrderDependencyNode> e = nodes.elements(); e.hasMoreElements();) {
CommitOrderDependencyNode n = e.nextElement();
if (n.getDescriptor() == d) {
return n;
}
Expand All @@ -189,13 +189,13 @@ public CommitOrderDependencyNode nodeFor(ClassDescriptor d) {
public void orderCommits() {
depthFirstSearch();

Object[] nodeArray = new Object[nodes.size()];
CommitOrderDependencyNode[] nodeArray = new CommitOrderDependencyNode[nodes.size()];
nodes.copyInto(nodeArray);

quicksort(nodeArray);
Vector result = new Vector(nodes.size());
for (int i = 0; i < nodes.size(); i++) {
CommitOrderDependencyNode node = (CommitOrderDependencyNode)nodeArray[i];
CommitOrderDependencyNode node = nodeArray[i];
result.addElement(node.getDescriptor());
}
this.orderedDescriptors = result;
Expand All @@ -211,7 +211,7 @@ private static void quicksort(Object[] arr) {
/**
* quicksort the array of objects.
*
* @param arr[] - an array of objects
* @param arr - an array of objects
* @param left - the start index - from where to begin sorting
* @param right - the last index.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -928,11 +928,11 @@ protected void buildRemoteCommandManagerConfig(RemoteCommandManagerConfig rcmCon
* INTERNAL:
*/
protected void buildTransportManager(TransportManagerConfig tmConfig, RemoteCommandManager rcm) {
if (tmConfig instanceof RMITransportManagerConfig) {
buildRMITransportManagerConfig((RMITransportManagerConfig)tmConfig, rcm);
} else if (tmConfig instanceof RMIIIOPTransportManagerConfig) {
if (tmConfig instanceof RMIIIOPTransportManagerConfig) {
buildRMIIIOPTransportManagerConfig((RMIIIOPTransportManagerConfig)tmConfig, rcm);
} else if (tmConfig instanceof JMSTopicTransportManagerConfig) {
} else if (tmConfig instanceof RMITransportManagerConfig) {
buildRMITransportManagerConfig((RMITransportManagerConfig)tmConfig, rcm);
} else if (tmConfig instanceof JMSTopicTransportManagerConfig) {
buildJMSTopicTransportManagerConfig((JMSTopicTransportManagerConfig)tmConfig, rcm);
} else if (tmConfig instanceof JMSPublishingTransportManagerConfig) {
buildJMSPublishingTransportManagerConfig((JMSPublishingTransportManagerConfig)tmConfig, rcm);
Expand Down
Loading

0 comments on commit 54abb16

Please sign in to comment.