Jetty 9.4.x spotbug issue map iteration using entrySet(), diamond list creation (#5804)
* fix some spotbug performance map iterations Signed-off-by: olivier lamy <oliver.lamy@gmail.com> * cannot use computeIfAbsent because it is a PathMap Signed-off-by: olivier lamy <oliver.lamy@gmail.com>
This commit is contained in:
parent
639cad63fe
commit
9343844f15
|
@ -163,7 +163,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
|
|||
if (pathSpec == null || "".equals(pathSpec.trim()) || constraintMappings == null || constraintMappings.size() == 0)
|
||||
return Collections.emptyList();
|
||||
|
||||
List<ConstraintMapping> mappings = new ArrayList<ConstraintMapping>();
|
||||
List<ConstraintMapping> mappings = new ArrayList<>();
|
||||
for (ConstraintMapping mapping : constraintMappings)
|
||||
{
|
||||
if (pathSpec.equals(mapping.getPathSpec()))
|
||||
|
@ -187,7 +187,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
|
|||
if (pathSpec == null || "".equals(pathSpec.trim()) || constraintMappings == null || constraintMappings.size() == 0)
|
||||
return Collections.emptyList();
|
||||
|
||||
List<ConstraintMapping> mappings = new ArrayList<ConstraintMapping>();
|
||||
List<ConstraintMapping> mappings = new ArrayList<>();
|
||||
for (ConstraintMapping mapping : constraintMappings)
|
||||
{
|
||||
//Remove the matching mappings by only copying in non-matching mappings
|
||||
|
@ -209,10 +209,10 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
|
|||
*/
|
||||
public static List<ConstraintMapping> createConstraintsWithMappingsForPath(String name, String pathSpec, ServletSecurityElement securityElement)
|
||||
{
|
||||
List<ConstraintMapping> mappings = new ArrayList<ConstraintMapping>();
|
||||
List<ConstraintMapping> mappings = new ArrayList<>();
|
||||
|
||||
//Create a constraint that will describe the default case (ie if not overridden by specific HttpMethodConstraints)
|
||||
Constraint httpConstraint = null;
|
||||
Constraint httpConstraint;
|
||||
ConstraintMapping httpConstraintMapping = null;
|
||||
|
||||
if (securityElement.getEmptyRoleSemantic() != EmptyRoleSemantic.PERMIT ||
|
||||
|
@ -229,7 +229,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
|
|||
}
|
||||
|
||||
//See Spec 13.4.1.2 p127
|
||||
List<String> methodOmissions = new ArrayList<String>();
|
||||
List<String> methodOmissions = new ArrayList<>();
|
||||
|
||||
//make constraint mappings for this url for each of the HttpMethodConstraintElements
|
||||
Collection<HttpMethodConstraintElement> methodConstraintElements = securityElement.getHttpMethodConstraints();
|
||||
|
@ -254,7 +254,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
|
|||
//See spec 13.4.1.2 p127 - add an omission for every method name to the default constraint
|
||||
//UNLESS the default constraint contains all default values. In that case, we won't add it. See Servlet Spec 3.1 pg 129
|
||||
if (methodOmissions.size() > 0 && httpConstraintMapping != null)
|
||||
httpConstraintMapping.setMethodOmissions(methodOmissions.toArray(new String[methodOmissions.size()]));
|
||||
httpConstraintMapping.setMethodOmissions(methodOmissions.toArray(new String[0]));
|
||||
|
||||
return mappings;
|
||||
}
|
||||
|
@ -435,9 +435,10 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
|
|||
protected void processConstraintMapping(ConstraintMapping mapping)
|
||||
{
|
||||
Map<String, RoleInfo> mappings = _constraintMap.get(mapping.getPathSpec());
|
||||
|
||||
if (mappings == null)
|
||||
{
|
||||
mappings = new HashMap<String, RoleInfo>();
|
||||
mappings = new HashMap<>();
|
||||
_constraintMap.put(mapping.getPathSpec(), mappings);
|
||||
}
|
||||
RoleInfo allMethodsRoleInfo = mappings.get(ALL_METHODS);
|
||||
|
@ -588,7 +589,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
|
|||
if (roleInfo == null)
|
||||
{
|
||||
//No specific http-method names matched
|
||||
List<RoleInfo> applicableConstraints = new ArrayList<RoleInfo>();
|
||||
List<RoleInfo> applicableConstraints = new ArrayList<>();
|
||||
|
||||
//Get info for constraint that matches all methods if it exists
|
||||
RoleInfo all = mappings.get(ALL_METHODS);
|
||||
|
@ -778,11 +779,11 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
|
|||
if (_denyUncoveredMethods)
|
||||
return Collections.emptySet();
|
||||
|
||||
Set<String> uncoveredPaths = new HashSet<String>();
|
||||
|
||||
for (String path : _constraintMap.keySet())
|
||||
Set<String> uncoveredPaths = new HashSet<>();
|
||||
for (Entry<String,Map<String, RoleInfo>> entry : _constraintMap.entrySet())
|
||||
{
|
||||
Map<String, RoleInfo> methodMappings = _constraintMap.get(path);
|
||||
Map<String, RoleInfo> methodMappings = entry.getValue();
|
||||
|
||||
//Each key is either:
|
||||
// : an exact method name
|
||||
// : * which means that the constraint applies to every method
|
||||
|
@ -790,7 +791,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
|
|||
if (methodMappings.get(ALL_METHODS) != null)
|
||||
continue; //can't be any uncovered methods for this url path
|
||||
|
||||
boolean hasOmissions = omissionsExist(path, methodMappings);
|
||||
boolean hasOmissions = omissionsExist(entry.getKey(), methodMappings);
|
||||
|
||||
for (String method : methodMappings.keySet())
|
||||
{
|
||||
|
@ -800,7 +801,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
|
|||
for (String m : omittedMethods)
|
||||
{
|
||||
if (!methodMappings.containsKey(m))
|
||||
uncoveredPaths.add(path);
|
||||
uncoveredPaths.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -808,7 +809,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
|
|||
//an exact method name
|
||||
if (!hasOmissions)
|
||||
//an http-method does not have http-method-omission to cover the other method names
|
||||
uncoveredPaths.add(path);
|
||||
uncoveredPaths.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -849,7 +850,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
|
|||
return Collections.emptySet();
|
||||
|
||||
String[] strings = omission.split("\\.");
|
||||
Set<String> methods = new HashSet<String>();
|
||||
Set<String> methods = new HashSet<>();
|
||||
for (int i = 0; i < strings.length - 1; i++)
|
||||
{
|
||||
methods.add(strings[i]);
|
||||
|
|
|
@ -71,13 +71,10 @@ public class Licensing
|
|||
System.err.printf(" + contains software not covered by the Eclipse Public License!%n");
|
||||
System.err.printf(" + has not been audited for compliance with its license%n");
|
||||
|
||||
for (String key : licenseMap.keySet())
|
||||
for (Map.Entry<String, List<String>> entry : licenseMap.entrySet())
|
||||
{
|
||||
System.err.printf("%n Module: %s%n", key);
|
||||
for (String line : licenseMap.get(key))
|
||||
{
|
||||
System.err.printf(" + %s%n", line);
|
||||
}
|
||||
System.err.printf("%n Module: %s%n", entry.getKey());
|
||||
entry.getValue().forEach(line -> System.err.printf(" + %s%n", line));
|
||||
}
|
||||
|
||||
boolean licenseAck = false;
|
||||
|
|
|
@ -181,8 +181,8 @@ public class Scanner extends AbstractLifeCycle
|
|||
if (rootIncludesExcludes != null && !rootIncludesExcludes.isEmpty())
|
||||
{
|
||||
//accepted if not explicitly excluded and either is explicitly included or there are no explicit inclusions
|
||||
Boolean result = rootIncludesExcludes.test(dir);
|
||||
if (Boolean.TRUE == result)
|
||||
boolean result = rootIncludesExcludes.test(dir);
|
||||
if (result)
|
||||
accepted = true;
|
||||
}
|
||||
else
|
||||
|
@ -215,8 +215,8 @@ public class Scanner extends AbstractLifeCycle
|
|||
if (rootIncludesExcludes != null && !rootIncludesExcludes.isEmpty())
|
||||
{
|
||||
//accepted if not explicitly excluded and either is explicitly included or there are no explicit inclusions
|
||||
Boolean result = rootIncludesExcludes.test(file);
|
||||
if (Boolean.TRUE == result)
|
||||
boolean result = rootIncludesExcludes.test(file);
|
||||
if (result)
|
||||
accepted = true;
|
||||
}
|
||||
else if (_filter == null || _filter.accept(f.getParentFile(), f.getName()))
|
||||
|
@ -663,11 +663,12 @@ public class Scanner extends AbstractLifeCycle
|
|||
public synchronized void scanFiles()
|
||||
{
|
||||
_currentScan.clear();
|
||||
for (Path p : _scannables.keySet())
|
||||
for (Entry<Path, IncludeExcludeSet<PathMatcher, Path>> entry : _scannables.entrySet())
|
||||
{
|
||||
Path p = entry.getKey();
|
||||
try
|
||||
{
|
||||
Files.walkFileTree(p, EnumSet.allOf(FileVisitOption.class),_scanDepth, new Visitor(p, _scannables.get(p), _currentScan));
|
||||
Files.walkFileTree(p, EnumSet.allOf(FileVisitOption.class),_scanDepth, new Visitor(p, entry.getValue(), _currentScan));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
|
|
|
@ -71,16 +71,9 @@ public class FragmentConfiguration extends AbstractConfiguration
|
|||
Map<Resource, Resource> frags = (Map<Resource, Resource>)context.getAttribute(FRAGMENT_RESOURCES);
|
||||
if (frags != null)
|
||||
{
|
||||
for (Resource key : frags.keySet())
|
||||
for (Map.Entry<Resource, Resource> entry : frags.entrySet())
|
||||
{
|
||||
if (key.isDirectory()) //tolerate the case where the library is a directory, not a jar. useful for OSGi for example
|
||||
{
|
||||
metaData.addFragment(key, frags.get(key));
|
||||
}
|
||||
else //the standard case: a jar most likely inside WEB-INF/lib
|
||||
{
|
||||
metaData.addFragment(key, frags.get(key));
|
||||
}
|
||||
metaData.addFragment(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,20 +44,20 @@ public class MetaData
|
|||
public static final String ORDERED_LIBS = "javax.servlet.context.orderedLibs";
|
||||
public static final Resource NON_FRAG_RESOURCE = EmptyResource.INSTANCE;
|
||||
|
||||
protected Map<String, OriginInfo> _origins = new HashMap<String, OriginInfo>();
|
||||
protected Map<String, OriginInfo> _origins = new HashMap<>();
|
||||
protected WebDescriptor _webDefaultsRoot;
|
||||
protected WebDescriptor _webXmlRoot;
|
||||
protected final List<WebDescriptor> _webOverrideRoots = new ArrayList<WebDescriptor>();
|
||||
protected final List<WebDescriptor> _webOverrideRoots = new ArrayList<>();
|
||||
protected boolean _metaDataComplete;
|
||||
protected final List<DescriptorProcessor> _descriptorProcessors = new ArrayList<DescriptorProcessor>();
|
||||
protected final List<FragmentDescriptor> _webFragmentRoots = new ArrayList<FragmentDescriptor>();
|
||||
protected final Map<String, FragmentDescriptor> _webFragmentNameMap = new HashMap<String, FragmentDescriptor>();
|
||||
protected final Map<Resource, FragmentDescriptor> _webFragmentResourceMap = new HashMap<Resource, FragmentDescriptor>();
|
||||
protected final Map<Resource, List<DiscoveredAnnotation>> _annotations = new HashMap<Resource, List<DiscoveredAnnotation>>();
|
||||
protected final List<Resource> _webInfClasses = new ArrayList<Resource>();
|
||||
protected final List<Resource> _webInfJars = new ArrayList<Resource>();
|
||||
protected final List<Resource> _orderedContainerResources = new ArrayList<Resource>();
|
||||
protected final List<Resource> _orderedWebInfResources = new ArrayList<Resource>();
|
||||
protected final List<DescriptorProcessor> _descriptorProcessors = new ArrayList<>();
|
||||
protected final List<FragmentDescriptor> _webFragmentRoots = new ArrayList<>();
|
||||
protected final Map<String, FragmentDescriptor> _webFragmentNameMap = new HashMap<>();
|
||||
protected final Map<Resource, FragmentDescriptor> _webFragmentResourceMap = new HashMap<>();
|
||||
protected final Map<Resource, List<DiscoveredAnnotation>> _annotations = new HashMap<>();
|
||||
protected final List<Resource> _webInfClasses = new ArrayList<>();
|
||||
protected final List<Resource> _webInfJars = new ArrayList<>();
|
||||
protected final List<Resource> _orderedContainerResources = new ArrayList<>();
|
||||
protected final List<Resource> _orderedWebInfResources = new ArrayList<>();
|
||||
protected Ordering _ordering;//can be set to RelativeOrdering by web-default.xml, web.xml, web-override.xml
|
||||
protected boolean _allowDuplicateFragmentNames = false;
|
||||
protected boolean _validateXml = false;
|
||||
|
@ -333,12 +333,8 @@ public class MetaData
|
|||
if (resource == null || !_webInfJars.contains(resource))
|
||||
resource = EmptyResource.INSTANCE;
|
||||
|
||||
List<DiscoveredAnnotation> list = _annotations.get(resource);
|
||||
if (list == null)
|
||||
{
|
||||
list = new ArrayList<DiscoveredAnnotation>();
|
||||
_annotations.put(resource, list);
|
||||
}
|
||||
List<DiscoveredAnnotation> list =
|
||||
_annotations.computeIfAbsent(resource, k -> new ArrayList<>());
|
||||
list.add(annotation);
|
||||
}
|
||||
|
||||
|
@ -378,7 +374,7 @@ public class MetaData
|
|||
if (getOrdering() != null)
|
||||
{
|
||||
orderedWebInfJars = getOrderedWebInfJars();
|
||||
List<String> orderedLibs = new ArrayList<String>();
|
||||
List<String> orderedLibs = new ArrayList<>();
|
||||
for (Resource webInfJar : orderedWebInfJars)
|
||||
{
|
||||
//get just the name of the jar file
|
||||
|
@ -545,10 +541,10 @@ public class MetaData
|
|||
return null;
|
||||
|
||||
Resource jar = null;
|
||||
for (Resource r : _webFragmentResourceMap.keySet())
|
||||
for (Map.Entry<Resource, FragmentDescriptor> entry : _webFragmentResourceMap.entrySet())
|
||||
{
|
||||
if (_webFragmentResourceMap.get(r).equals(f))
|
||||
jar = r;
|
||||
if (entry.getValue().equals(f))
|
||||
jar = entry.getKey();
|
||||
}
|
||||
return jar;
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ public class XmlAppendable
|
|||
{
|
||||
_out = out;
|
||||
_indent = indent;
|
||||
_out.append("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n");
|
||||
_out.append("<?xml version=\"1.0\" encoding=\"").append(encoding).append("\"?>\n");
|
||||
}
|
||||
|
||||
public XmlAppendable openTag(String tag, Map<String, String> attributes) throws IOException
|
||||
|
@ -153,11 +153,10 @@ public class XmlAppendable
|
|||
|
||||
private void attributes(Map<String, String> attributes) throws IOException
|
||||
{
|
||||
for (String k : attributes.keySet())
|
||||
for (Map.Entry<String, String> entry : attributes.entrySet())
|
||||
{
|
||||
String v = attributes.get(k);
|
||||
_out.append(' ').append(k).append("=\"");
|
||||
content(v);
|
||||
_out.append(' ').append(entry.getKey()).append("=\"");
|
||||
content(entry.getValue());
|
||||
_out.append('"');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1884,10 +1884,9 @@ public class XmlConfiguration
|
|||
if (properties.size() > 0)
|
||||
{
|
||||
Map<String, String> props = new HashMap<>();
|
||||
for (Object key : properties.keySet())
|
||||
{
|
||||
props.put(key.toString(), String.valueOf(properties.get(key)));
|
||||
}
|
||||
properties.entrySet().stream()
|
||||
.forEach(objectObjectEntry -> props.put(objectObjectEntry.getKey().toString(),
|
||||
String.valueOf(objectObjectEntry.getValue())));
|
||||
configuration.getProperties().putAll(props);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue