Sonar critical bug: inefficient use of keySet iterator instead of entrySet iterator

This commit is contained in:
cagache
2019-07-02 12:06:13 +03:00
parent 7782d7d448
commit 6e2826f78c
3 changed files with 12 additions and 15 deletions

View File

@@ -1022,13 +1022,12 @@ public class RMCaveatConfigComponentImpl implements ContentServicePolicies.OnCon
for (String listName : listNames) for (String listName : listNames)
{ {
Map<String, List<String>> members = config.get(listName); Map<String, List<String>> members = config.get(listName);
Set<String> authorityNames = members.keySet();
JSONObject listMembers = new JSONObject(); JSONObject listMembers = new JSONObject();
for (String authorityName : authorityNames) for (Map.Entry<String, List<String>> member : members.entrySet())
{ {
List<String> authorities = members.get(authorityName); final String authorityName = member.getKey();
final List<String> authorities = member.getValue();
try try
{ {
listMembers.put(authorityName, authorities); listMembers.put(authorityName, authorities);

View File

@@ -97,15 +97,12 @@ public class ScriptConstraint implements Serializable
return new ScriptConstraintAuthority[0]; return new ScriptConstraintAuthority[0];
} }
// Here with some data to return
Set<String> authorities = values.keySet();
ArrayList<ScriptConstraintAuthority> constraints = new ArrayList<>(values.size()); ArrayList<ScriptConstraintAuthority> constraints = new ArrayList<>(values.size());
for(String authority : authorities) for (Map.Entry<String, List<String>> entry : values.entrySet())
{ {
ScriptConstraintAuthority constraint = new ScriptConstraintAuthority(); ScriptConstraintAuthority constraint = new ScriptConstraintAuthority();
constraint.setAuthorityName(authority); constraint.setAuthorityName(entry.getKey());
constraint.setValues(values.get(authority)); constraint.setValues(entry.getValue());
constraints.add(constraint); constraints.add(constraint);
} }

View File

@@ -255,22 +255,23 @@ public final class RecordsManagementAuditEntry
this.beforeProperties.size() + this.afterProperties.size()); this.beforeProperties.size() + this.afterProperties.size());
// add all the properties present before the audited action // add all the properties present before the audited action
for (QName valuePropName : this.beforeProperties.keySet()) for (Map.Entry<QName, Serializable> entry : this.beforeProperties.entrySet())
{ {
final QName valuePropName = entry.getKey();
Pair<Serializable, Serializable> values = new Pair<>( Pair<Serializable, Serializable> values = new Pair<>(
this.beforeProperties.get(valuePropName), entry.getValue(),
this.afterProperties.get(valuePropName)); this.afterProperties.get(valuePropName));
this.changedProperties.put(valuePropName, values); this.changedProperties.put(valuePropName, values);
} }
// add all the properties present after the audited action that // add all the properties present after the audited action that
// have not already been added // have not already been added
for (QName valuePropName : this.afterProperties.keySet()) for (Map.Entry<QName, Serializable> entry : this.afterProperties.entrySet())
{ {
final QName valuePropName = entry.getKey();
if (!this.beforeProperties.containsKey(valuePropName)) if (!this.beforeProperties.containsKey(valuePropName))
{ {
Pair<Serializable, Serializable> values = new Pair<>(null, Pair<Serializable, Serializable> values = new Pair<>(null, entry.getValue());
this.afterProperties.get(valuePropName));
this.changedProperties.put(valuePropName, values); this.changedProperties.put(valuePropName, values);
} }
} }