diff --git a/impl/src/main/java/com/sun/faces/application/ActionListenerImpl.java b/impl/src/main/java/com/sun/faces/application/ActionListenerImpl.java
index 45a9fa707d..a8768693d0 100644
--- a/impl/src/main/java/com/sun/faces/application/ActionListenerImpl.java
+++ b/impl/src/main/java/com/sun/faces/application/ActionListenerImpl.java
@@ -78,7 +78,7 @@ private String getNavigationOutcome(FacesContext context, MethodExpression expre
return invokeResult.toString();
} catch (ELException | NullPointerException e) {
- LOGGER.log(FINE, e, () -> e.getMessage());
+ LOGGER.log(FINE, e, e::getMessage);
throw new FacesException(expression.getExpressionString() + ": " + e.getMessage(), e);
}
diff --git a/impl/src/main/java/com/sun/faces/application/NavigationHandlerImpl.java b/impl/src/main/java/com/sun/faces/application/NavigationHandlerImpl.java
index 106ae7f8ad..a653adfd46 100644
--- a/impl/src/main/java/com/sun/faces/application/NavigationHandlerImpl.java
+++ b/impl/src/main/java/com/sun/faces/application/NavigationHandlerImpl.java
@@ -256,8 +256,8 @@ public void handleNavigation(FacesContext context, String fromAction, String out
// If we are exiting all flows
if (caseStruct.newFlow == null) { // NOPMD
- parameters.put(TO_FLOW_DOCUMENT_ID_REQUEST_PARAM_NAME, asList(NULL_FLOW));
- parameters.put(FLOW_ID_REQUEST_PARAM_NAME, asList(""));
+ parameters.put(TO_FLOW_DOCUMENT_ID_REQUEST_PARAM_NAME, List.of(NULL_FLOW));
+ parameters.put(FLOW_ID_REQUEST_PARAM_NAME, List.of(""));
FlowHandler flowHandler = context.getApplication().getFlowHandler();
if (flowHandler instanceof FlowHandlerImpl) {
@@ -272,10 +272,10 @@ public void handleNavigation(FacesContext context, String fromAction, String out
if (!parameters.containsKey(TO_FLOW_DOCUMENT_ID_REQUEST_PARAM_NAME) || !parameters.containsKey(FLOW_ID_REQUEST_PARAM_NAME)) {
// Overwrite both of them.
- List toFlowDocumentIdParam = asList(caseStruct.navCase.getToFlowDocumentId());
+ List toFlowDocumentIdParam = Collections.singletonList(caseStruct.navCase.getToFlowDocumentId());
parameters.put(TO_FLOW_DOCUMENT_ID_REQUEST_PARAM_NAME, toFlowDocumentIdParam);
- List flowIdParam = asList(caseStruct.newFlow.getId());
+ List flowIdParam = Collections.singletonList(caseStruct.newFlow.getId());
parameters.put(FLOW_ID_REQUEST_PARAM_NAME, flowIdParam);
}
}
@@ -866,8 +866,8 @@ private CaseStruct findImplicitMatch(FacesContext context, String viewId, String
Map appMap = context.getExternalContext().getApplicationMap();
String[] queryElements = Util.split(appMap, queryString, "&|&");
- for (int i = 0, len = queryElements.length; i < len; i++) {
- String[] elements = Util.split(appMap, queryElements[i], "=", 2);
+ for (String queryElement : queryElements) {
+ String[] elements = Util.split(appMap, queryElement, "=", 2);
if (elements.length == 2) {
String rightHandSide = elements[1];
String sanitized = null != rightHandSide && 2 < rightHandSide.length() ? rightHandSide.trim() : "";
@@ -877,19 +877,13 @@ private CaseStruct findImplicitMatch(FacesContext context, String viewId, String
}
rightHandSide = "";
}
+
if (parameters == null) {
- parameters = new LinkedHashMap<>(len / 2, 1.0f);
- List values = new ArrayList<>(2);
- values.add(rightHandSide);
- parameters.put(elements[0], values);
- } else {
- List values = parameters.get(elements[0]);
- if (values == null) {
- values = new ArrayList<>(2);
- parameters.put(elements[0], values);
- }
- values.add(rightHandSide);
+ parameters = new LinkedHashMap<>(queryElements.length / 2, 1.0f);
}
+
+ parameters.computeIfAbsent(elements[0], k -> new ArrayList<>(2))
+ .add(rightHandSide);
}
}
}
@@ -1278,7 +1272,7 @@ private CaseStruct findViewNodeMatch(FacesContext context, String fromAction, St
Flow currentFlow = flowHandler.getCurrentFlow(context);
if (null != currentFlow) {
FlowNode node = currentFlow.getNode(outcome);
- if (null != node && node instanceof ViewNode) {
+ if (node instanceof ViewNode) {
result = synthesizeCaseStruct(context, currentFlow, fromAction, outcome);
}
}
@@ -1418,8 +1412,8 @@ private static final class NavigationInfo {
private static final class NavigationMap extends AbstractMap> {
- private HashMap> mapToLookForNavCase = new HashMap<>();
- private TreeSet wildcardMatchList = new TreeSet<>((fromViewId1, fromViewId2) -> -fromViewId1.compareTo(fromViewId2));
+ private final HashMap> mapToLookForNavCase = new HashMap<>();
+ private final TreeSet wildcardMatchList = new TreeSet<>((fromViewId1, fromViewId2) -> -fromViewId1.compareTo(fromViewId2));
// ---------------------------------------------------- Methods from Map
@@ -1472,11 +1466,11 @@ public void putAll(Map extends String, ? extends Set> m) {
@Override
public Set keySet() {
- return new AbstractSet() {
+ return new AbstractSet<>() {
@Override
public Iterator iterator() {
- return new Iterator() {
+ return new Iterator<>() {
Iterator>> i = entrySet().iterator();
@@ -1506,11 +1500,11 @@ public int size() {
@Override
public Collection> values() {
- return new AbstractCollection>() {
+ return new AbstractCollection<>() {
@Override
public Iterator> iterator() {
- return new Iterator>() {
+ return new Iterator<>() {
Iterator>> i = entrySet().iterator();
@@ -1540,12 +1534,12 @@ public int size() {
@Override
public Set>> entrySet() {
- return new AbstractSet>>() {
+ return new AbstractSet<>() {
@Override
public Iterator>> iterator() {
- return new Iterator>>() {
+ return new Iterator<>() {
Iterator>> i = mapToLookForNavCase.entrySet().iterator();
diff --git a/impl/src/main/java/com/sun/faces/application/applicationimpl/events/SystemEventHelper.java b/impl/src/main/java/com/sun/faces/application/applicationimpl/events/SystemEventHelper.java
index aa57ca4849..95bdc187e5 100644
--- a/impl/src/main/java/com/sun/faces/application/applicationimpl/events/SystemEventHelper.java
+++ b/impl/src/main/java/com/sun/faces/application/applicationimpl/events/SystemEventHelper.java
@@ -31,7 +31,7 @@ public class SystemEventHelper {
public SystemEventHelper() {
- systemEventInfoCache = new Cache<>(arg -> new SystemEventInfo(arg));
+ systemEventInfoCache = new Cache<>(SystemEventInfo::new);
}
diff --git a/impl/src/main/java/com/sun/faces/application/view/FaceletFullStateManagementStrategy.java b/impl/src/main/java/com/sun/faces/application/view/FaceletFullStateManagementStrategy.java
index 96b7b8be92..22cbc0b0fd 100644
--- a/impl/src/main/java/com/sun/faces/application/view/FaceletFullStateManagementStrategy.java
+++ b/impl/src/main/java/com/sun/faces/application/view/FaceletFullStateManagementStrategy.java
@@ -860,7 +860,7 @@ public int getParent() {
private int getProperChildIndex(UIComponent component) {
int result = -1;
- if (component.getParent().getChildren().indexOf(component) != -1) {
+ if (component.getParent().getChildren().contains(component)) {
UIComponent parent = component.getParent();
int index = 0;
Iterator iterator = parent.getChildren().iterator();
diff --git a/impl/src/main/java/com/sun/faces/component/PassthroughElement.java b/impl/src/main/java/com/sun/faces/component/PassthroughElement.java
index 98ef132021..1477965b2b 100644
--- a/impl/src/main/java/com/sun/faces/component/PassthroughElement.java
+++ b/impl/src/main/java/com/sun/faces/component/PassthroughElement.java
@@ -357,8 +357,8 @@ public void setStyleClass(java.lang.String styleClass) {
getStateHelper().put(PropertyKeys.styleClass, styleClass);
}
- private static final Collection EVENT_NAMES = Collections.unmodifiableCollection(
- Arrays.asList("click", "dblclick", "keydown", "keypress", "keyup", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup"));
+ private static final List EVENT_NAMES = List.of(
+ "click", "dblclick", "keydown", "keypress", "keyup", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup");
@Override
public Collection getEventNames() {
@@ -376,7 +376,7 @@ private void handleAttribute(String name, Object value) {
List setAttributes = (List) getAttributes().get("jakarta.faces.component.UIComponentBase.attributesThatAreSet");
if (setAttributes == null) {
String cname = this.getClass().getName();
- if (cname != null && cname.startsWith(OPTIMIZED_PACKAGE)) {
+ if (cname.startsWith(OPTIMIZED_PACKAGE)) {
setAttributes = new ArrayList<>(6);
getAttributes().put("jakarta.faces.component.UIComponentBase.attributesThatAreSet", setAttributes);
}
diff --git a/impl/src/main/java/com/sun/faces/component/search/CompositeSearchKeywordResolver.java b/impl/src/main/java/com/sun/faces/component/search/CompositeSearchKeywordResolver.java
index 9f8deb680f..c1c86e2a13 100644
--- a/impl/src/main/java/com/sun/faces/component/search/CompositeSearchKeywordResolver.java
+++ b/impl/src/main/java/com/sun/faces/component/search/CompositeSearchKeywordResolver.java
@@ -46,8 +46,7 @@ public void add(SearchKeywordResolver searchKeywordResolver) {
public void resolve(SearchKeywordContext context, UIComponent current, String keyword) {
context.setKeywordResolved(false);
- for (int i = 0; i < resolvers.size(); i++) {
- SearchKeywordResolver resolver = resolvers.get(i);
+ for (SearchKeywordResolver resolver : resolvers) {
if (resolver.isResolverForKeyword(context.getSearchExpressionContext(), keyword)) {
resolver.resolve(context, current, keyword);
if (context.isKeywordResolved()) {
@@ -59,8 +58,7 @@ public void resolve(SearchKeywordContext context, UIComponent current, String ke
@Override
public boolean isResolverForKeyword(SearchExpressionContext searchExpressionContext, String keyword) {
- for (int i = 0; i < resolvers.size(); i++) {
- SearchKeywordResolver resolver = resolvers.get(i);
+ for (SearchKeywordResolver resolver : resolvers) {
if (resolver.isResolverForKeyword(searchExpressionContext, keyword)) {
return true;
}
@@ -71,8 +69,7 @@ public boolean isResolverForKeyword(SearchExpressionContext searchExpressionCont
@Override
public boolean isPassthrough(SearchExpressionContext searchExpressionContext, String keyword) {
- for (int i = 0; i < resolvers.size(); i++) {
- SearchKeywordResolver resolver = resolvers.get(i);
+ for (SearchKeywordResolver resolver : resolvers) {
if (resolver.isResolverForKeyword(searchExpressionContext, keyword)) {
return resolver.isPassthrough(searchExpressionContext, keyword);
}
@@ -83,8 +80,7 @@ public boolean isPassthrough(SearchExpressionContext searchExpressionContext, St
@Override
public boolean isLeaf(SearchExpressionContext searchExpressionContext, String keyword) {
- for (int i = 0; i < resolvers.size(); i++) {
- SearchKeywordResolver resolver = resolvers.get(i);
+ for (SearchKeywordResolver resolver : resolvers) {
if (resolver.isResolverForKeyword(searchExpressionContext, keyword)) {
return resolver.isLeaf(searchExpressionContext, keyword);
}
diff --git a/impl/src/main/java/com/sun/faces/component/search/SearchExpressionHandlerImpl.java b/impl/src/main/java/com/sun/faces/component/search/SearchExpressionHandlerImpl.java
index f12fb58297..e701e0e793 100644
--- a/impl/src/main/java/com/sun/faces/component/search/SearchExpressionHandlerImpl.java
+++ b/impl/src/main/java/com/sun/faces/component/search/SearchExpressionHandlerImpl.java
@@ -34,10 +34,8 @@
public class SearchExpressionHandlerImpl extends SearchExpressionHandler {
protected void addHint(SearchExpressionContext searchExpressionContext, SearchExpressionHint hint) {
- // It is a Set already
- if (!searchExpressionContext.getExpressionHints().contains(hint)) {
- searchExpressionContext.getExpressionHints().add(hint);
- }
+ // It is a Set already, it will add only if just not contains the hint
+ searchExpressionContext.getExpressionHints().add(hint);
}
@Override
diff --git a/impl/src/main/java/com/sun/faces/component/visit/PartialVisitContext.java b/impl/src/main/java/com/sun/faces/component/visit/PartialVisitContext.java
index ff6e7d9386..4aaf92fe92 100644
--- a/impl/src/main/java/com/sun/faces/component/visit/PartialVisitContext.java
+++ b/impl/src/main/java/com/sun/faces/component/visit/PartialVisitContext.java
@@ -230,7 +230,7 @@ private void initializeCollections(Collection clientIds) {
// Initialize ids collection
ids = new HashSet<>();
- // Intialize subtreeClientIds collection
+ // Initialize subtreeClientIds collection
subtreeClientIds = new HashMap<>();
// Initialize the clientIds collection. Note that we proxy
@@ -265,8 +265,8 @@ private String getVisitId(UIComponent component) {
return clientIds.contains(clientId) ? clientId : null;
}
- // Converts an client id into a plain old id by ripping
- // out the trailing id segmetn.
+ // Converts a client id into a plain old id by ripping
+ // out the trailing id segment.
private String getIdFromClientId(String clientId) {
FacesContext facesContext = getFacesContext();
char separator = UINamingContainer.getSeparatorChar(facesContext);
@@ -309,12 +309,7 @@ private void addSubtreeClientId(String clientId) {
// NamingContainer client id. If not, create the
// Collection for this NamingContainer client id and
// stash it away in our map
- Collection c = subtreeClientIds.get(namingContainerClientId);
-
- if (c == null) {
- c = new ArrayList<>();
- subtreeClientIds.put(namingContainerClientId, c);
- }
+ Collection c = subtreeClientIds.computeIfAbsent(namingContainerClientId, k -> new ArrayList<>());
// Stash away the client id
c.add(clientId);
@@ -373,7 +368,7 @@ public boolean add(E o) {
return added;
}
- private Collection wrapped;
+ private final Collection wrapped;
}
// Little proxy iterator implementation used by CollectionProxy
@@ -405,7 +400,7 @@ public void remove() {
wrapped.remove();
}
- private Iterator wrapped;
+ private final Iterator wrapped;
private E current = null;
}
@@ -426,8 +421,8 @@ public void remove() {
private Map> subtreeClientIds;
// The FacesContext for this request
- private FacesContext facesContext;
+ private final FacesContext facesContext;
// Our visit hints
- private Set hints;
+ private final Set hints;
}
diff --git a/impl/src/main/java/com/sun/faces/config/configprovider/MetaInfFaceletTaglibraryConfigProvider.java b/impl/src/main/java/com/sun/faces/config/configprovider/MetaInfFaceletTaglibraryConfigProvider.java
index 2900ef7e95..5e2d20f7b2 100644
--- a/impl/src/main/java/com/sun/faces/config/configprovider/MetaInfFaceletTaglibraryConfigProvider.java
+++ b/impl/src/main/java/com/sun/faces/config/configprovider/MetaInfFaceletTaglibraryConfigProvider.java
@@ -64,7 +64,7 @@ public Collection getResources(ServletContext context) {
}
return resourceURLs.stream()
- .map(url -> transformToURI(url))
+ .map(this::transformToURI)
.collect(toList());
} catch (IOException ioe) {
diff --git a/impl/src/main/java/com/sun/faces/config/configprovider/MetaInfFacesConfigResourceProvider.java b/impl/src/main/java/com/sun/faces/config/configprovider/MetaInfFacesConfigResourceProvider.java
index 40501e2257..0930ae2249 100644
--- a/impl/src/main/java/com/sun/faces/config/configprovider/MetaInfFacesConfigResourceProvider.java
+++ b/impl/src/main/java/com/sun/faces/config/configprovider/MetaInfFacesConfigResourceProvider.java
@@ -98,11 +98,7 @@ public Collection getResources(ServletContext context) {
}
}
- Set uris = sortedJarMap.get(jarName);
- if (uris == null) {
- uris = new HashSet<>();
- sortedJarMap.put(jarName, uris);
- }
+ Set uris = sortedJarMap.computeIfAbsent(jarName, k -> new HashSet<>());
uris.add(uri);
} else {
unsortedResourceList.add(0, uri);
@@ -141,7 +137,7 @@ private Collection loadURLs(ServletContext context) throws IOException {
urls.add(new URI(urlString));
}
// special case for finding taglib files in WEB-INF/classes/META-INF
- Set paths = context.getResourcePaths(WEB_INF_CLASSES);
+ Set paths = context.getResourcePaths(WEB_INF_CLASSES);
if (paths != null) {
for (Object path : paths) {
String p = path.toString();
diff --git a/impl/src/main/java/com/sun/faces/config/configprovider/WebAppFlowConfigResourceProvider.java b/impl/src/main/java/com/sun/faces/config/configprovider/WebAppFlowConfigResourceProvider.java
index 8a6a6c349d..1c5d9864bd 100644
--- a/impl/src/main/java/com/sun/faces/config/configprovider/WebAppFlowConfigResourceProvider.java
+++ b/impl/src/main/java/com/sun/faces/config/configprovider/WebAppFlowConfigResourceProvider.java
@@ -74,7 +74,7 @@ public Collection getResources(ServletContext context) {
}
}
- return null == list ? Collections.EMPTY_LIST : list;
+ return null == list ? Collections.emptyList() : list;
}
diff --git a/impl/src/main/java/com/sun/faces/config/initfacescontext/NoOpFacesContext.java b/impl/src/main/java/com/sun/faces/config/initfacescontext/NoOpFacesContext.java
index 01e7ca954c..5ba821e307 100644
--- a/impl/src/main/java/com/sun/faces/config/initfacescontext/NoOpFacesContext.java
+++ b/impl/src/main/java/com/sun/faces/config/initfacescontext/NoOpFacesContext.java
@@ -16,6 +16,7 @@
package com.sun.faces.config.initfacescontext;
+import static java.util.Collections.emptyIterator;
import static java.util.Collections.emptyList;
import java.util.Iterator;
@@ -38,8 +39,7 @@ public Lifecycle getLifecycle() {
@Override
public Iterator getClientIdsWithMessages() {
- List list = emptyList();
- return list.iterator();
+ return emptyIterator();
}
@Override
@@ -49,8 +49,7 @@ public FacesMessage.Severity getMaximumSeverity() {
@Override
public Iterator getMessages() {
- List list = emptyList();
- return list.iterator();
+ return emptyIterator();
}
@Override
diff --git a/impl/src/main/java/com/sun/faces/config/initfacescontext/ServletContextAdapter.java b/impl/src/main/java/com/sun/faces/config/initfacescontext/ServletContextAdapter.java
index b8bd6de4b9..2f2525564e 100644
--- a/impl/src/main/java/com/sun/faces/config/initfacescontext/ServletContextAdapter.java
+++ b/impl/src/main/java/com/sun/faces/config/initfacescontext/ServletContextAdapter.java
@@ -195,17 +195,17 @@ public Map getRequestMap() {
@Override
public Map getRequestParameterMap() {
- return unmodifiableMap(emptyMap());
+ return emptyMap();
}
@Override
public Iterator getRequestParameterNames() {
- return Collections.emptyList().iterator();
+ return Collections.emptyIterator();
}
@Override
public Map getRequestParameterValuesMap() {
- return unmodifiableMap(emptyMap());
+ return emptyMap();
}
@Override
diff --git a/impl/src/main/java/com/sun/faces/config/manager/DbfFactory.java b/impl/src/main/java/com/sun/faces/config/manager/DbfFactory.java
index 4e9011d019..fd9348a0b5 100644
--- a/impl/src/main/java/com/sun/faces/config/manager/DbfFactory.java
+++ b/impl/src/main/java/com/sun/faces/config/manager/DbfFactory.java
@@ -129,7 +129,7 @@ public FacesEntityResolver() {
try {
schemaUrl = schemaFile.toURI().toURL();
} catch (MalformedURLException mue) {
- LOGGER.log(SEVERE, mue, () -> mue.toString());
+ LOGGER.log(SEVERE, mue, mue::toString);
}
if (schemaUrl == null) {
@@ -353,7 +353,7 @@ private static Map getSchemaMap(ServletContext servletConte
if (schemaMap == null) {
synchronized (servletContext) {
- schemaMap = synchronizedMap(new EnumMap(FacesSchema.class));
+ schemaMap = synchronizedMap(new EnumMap<>(FacesSchema.class));
servletContext.setAttribute(SCHEMA_MAP, schemaMap);
}
}
diff --git a/impl/src/main/java/com/sun/faces/config/manager/spi/AnnotationScanner.java b/impl/src/main/java/com/sun/faces/config/manager/spi/AnnotationScanner.java
index 80ebe79b38..9cdfd86d83 100644
--- a/impl/src/main/java/com/sun/faces/config/manager/spi/AnnotationScanner.java
+++ b/impl/src/main/java/com/sun/faces/config/manager/spi/AnnotationScanner.java
@@ -65,7 +65,7 @@ public abstract class AnnotationScanner extends AnnotationProvider {
private static final Logger LOGGER = FacesLogger.CONFIG.getLogger();
private static final String WILDCARD = "*";
- protected static final Set FACES_ANNOTATIONS = unmodifiableSet(new HashSet<>(asList(
+ protected static final Set FACES_ANNOTATIONS = Set.of(
"Ljakarta/faces/component/FacesComponent;", "Ljakarta/faces/convert/FacesConverter;",
"Ljakarta/faces/validator/FacesValidator;", "Ljakarta/faces/render/FacesRenderer;",
"Ljakarta/faces/event/NamedEvent;", "Ljakarta/faces/component/behavior/FacesBehavior;",
@@ -74,13 +74,13 @@ public abstract class AnnotationScanner extends AnnotationProvider {
"jakarta.faces.component.FacesComponent", "jakarta.faces.convert.FacesConverter",
"jakarta.faces.validator.FacesValidator", "jakarta.faces.render.FacesRenderer",
"jakarta.faces.event.NamedEvent", "jakarta.faces.component.behavior.FacesBehavior",
- "jakarta.faces.render.FacesBehaviorRenderer")));
+ "jakarta.faces.render.FacesBehaviorRenderer");
- protected static final Set> FACES_ANNOTATION_TYPE = unmodifiableSet(new HashSet<>(asList(
+ protected static final Set> FACES_ANNOTATION_TYPE = Set.of(
FacesComponent.class, FacesConverter.class,
FacesValidator.class, FacesRenderer.class,
NamedEvent.class, FacesBehavior.class,
- FacesBehaviorRenderer.class)));
+ FacesBehaviorRenderer.class);
private boolean isAnnotationScanPackagesSet;
private String[] webInfClassesPackages;
@@ -207,11 +207,7 @@ protected Map, Set>> processClassList(Set annoType = annotation.annotationType();
if (FACES_ANNOTATION_TYPE.contains(annoType)) {
- Set> classes = annotatedClasses.get(annoType);
- if (classes == null) {
- classes = new HashSet<>();
- annotatedClasses.put(annoType, classes);
- }
+ Set> classes = annotatedClasses.computeIfAbsent(annoType, k -> new HashSet<>());
classes.add(clazz);
}
}
diff --git a/impl/src/main/java/com/sun/faces/config/processor/AbstractConfigProcessor.java b/impl/src/main/java/com/sun/faces/config/processor/AbstractConfigProcessor.java
index 37503a0c5a..b75123fab8 100644
--- a/impl/src/main/java/com/sun/faces/config/processor/AbstractConfigProcessor.java
+++ b/impl/src/main/java/com/sun/faces/config/processor/AbstractConfigProcessor.java
@@ -138,8 +138,7 @@ protected Map getTextMap(List list) {
if (list != null && !list.isEmpty()) {
int len = list.size();
HashMap names = new HashMap<>(len, 1.0f);
- for (int i = 0; i < len; i++) {
- Node node = list.get(i);
+ for (Node node : list) {
String textValue = getNodeText(node);
if (textValue != null) {
if (node.hasAttributes()) {
diff --git a/impl/src/main/java/com/sun/faces/config/processor/ApplicationConfigProcessor.java b/impl/src/main/java/com/sun/faces/config/processor/ApplicationConfigProcessor.java
index 7fe54ab229..9b8824268c 100644
--- a/impl/src/main/java/com/sun/faces/config/processor/ApplicationConfigProcessor.java
+++ b/impl/src/main/java/com/sun/faces/config/processor/ApplicationConfigProcessor.java
@@ -378,9 +378,9 @@ static boolean isBeanValidatorAvailable(FacesContext facesContext) {
} catch (NoClassDefFoundError nde) {
// On google app engine InitialContext is forbidden to use and GAE throws
// NoClassDefFoundError
- LOGGER.log(FINE, nde, () -> nde.toString());
+ LOGGER.log(FINE, nde, nde::toString);
} catch (NamingException ne) {
- LOGGER.log(WARNING, ne, () -> ne.toString());
+ LOGGER.log(WARNING, ne, ne::toString);
}
try {
diff --git a/impl/src/main/java/com/sun/faces/config/processor/BehaviorConfigProcessor.java b/impl/src/main/java/com/sun/faces/config/processor/BehaviorConfigProcessor.java
index 682ad40c18..e918cfa01c 100644
--- a/impl/src/main/java/com/sun/faces/config/processor/BehaviorConfigProcessor.java
+++ b/impl/src/main/java/com/sun/faces/config/processor/BehaviorConfigProcessor.java
@@ -78,11 +78,11 @@ public void process(ServletContext sc, FacesContext facesContext, DocumentInfo[]
// via config files take precedence
processAnnotations(facesContext, FacesBehavior.class);
- for (int i = 0; i < documentInfos.length; i++) {
+ for (DocumentInfo documentInfo : documentInfos) {
if (LOGGER.isLoggable(FINE)) {
- LOGGER.log(FINE, format("Processing behavior elements for document: ''{0}''", documentInfos[i].getSourceURI()));
+ LOGGER.log(FINE, format("Processing behavior elements for document: ''{0}''", documentInfo.getSourceURI()));
}
- Document document = documentInfos[i].getDocument();
+ Document document = documentInfo.getDocument();
String namespace = document.getDocumentElement().getNamespaceURI();
NodeList behaviors = document.getDocumentElement().getElementsByTagNameNS(namespace, BEHAVIOR);
if (behaviors != null && behaviors.getLength() > 0) {
diff --git a/impl/src/main/java/com/sun/faces/config/processor/ComponentConfigProcessor.java b/impl/src/main/java/com/sun/faces/config/processor/ComponentConfigProcessor.java
index b78dfb547b..fd6bb21a9c 100644
--- a/impl/src/main/java/com/sun/faces/config/processor/ComponentConfigProcessor.java
+++ b/impl/src/main/java/com/sun/faces/config/processor/ComponentConfigProcessor.java
@@ -78,12 +78,12 @@ public void process(ServletContext sc, FacesContext facesContext, DocumentInfo[]
// via config files take precedence
processAnnotations(facesContext, FacesComponent.class);
- for (int i = 0; i < documentInfos.length; i++) {
+ for (DocumentInfo documentInfo : documentInfos) {
if (LOGGER.isLoggable(FINE)) {
- LOGGER.log(FINE, format("Processing component elements for document: ''{0}''", documentInfos[i].getSourceURI()));
+ LOGGER.log(FINE, format("Processing component elements for document: ''{0}''", documentInfo.getSourceURI()));
}
- Document document = documentInfos[i].getDocument();
+ Document document = documentInfo.getDocument();
String namespace = document.getDocumentElement().getNamespaceURI();
NodeList components = document.getDocumentElement().getElementsByTagNameNS(namespace, COMPONENT);
if (components != null && components.getLength() > 0) {
diff --git a/impl/src/main/java/com/sun/faces/config/processor/FacesConfigNamespaceContext.java b/impl/src/main/java/com/sun/faces/config/processor/FacesConfigNamespaceContext.java
index 634b00303d..091bcea2c5 100644
--- a/impl/src/main/java/com/sun/faces/config/processor/FacesConfigNamespaceContext.java
+++ b/impl/src/main/java/com/sun/faces/config/processor/FacesConfigNamespaceContext.java
@@ -23,7 +23,7 @@
class FacesConfigNamespaceContext implements NamespaceContext {
- private String defaultNamespace = null;
+ private final String defaultNamespace;
FacesConfigNamespaceContext() {
this.defaultNamespace = "https://jakarta.ee/xml/ns/jakartaee";
@@ -45,7 +45,7 @@ public String getPrefix(String namespaceURI) {
@Override
public Iterator getPrefixes(String namespaceURI) {
- return Collections.emptyList().iterator();
+ return Collections.emptyIterator();
}
}
diff --git a/impl/src/main/java/com/sun/faces/config/processor/FacesFlowDefinitionConfigProcessor.java b/impl/src/main/java/com/sun/faces/config/processor/FacesFlowDefinitionConfigProcessor.java
index 77da79922c..ff7308dad6 100644
--- a/impl/src/main/java/com/sun/faces/config/processor/FacesFlowDefinitionConfigProcessor.java
+++ b/impl/src/main/java/com/sun/faces/config/processor/FacesFlowDefinitionConfigProcessor.java
@@ -160,12 +160,12 @@ public void process(ServletContext sc, FacesContext facesContext, DocumentInfo[]
WebConfiguration config = WebConfiguration.getInstance(sc);
- for (int i = 0; i < documentInfos.length; i++) {
- URI definingDocumentURI = documentInfos[i].getSourceURI();
+ for (DocumentInfo documentInfo : documentInfos) {
+ URI definingDocumentURI = documentInfo.getSourceURI();
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, MessageFormat.format("Processing factory elements for document: ''{0}''", definingDocumentURI));
}
- Document document = documentInfos[i].getDocument();
+ Document document = documentInfo.getDocument();
String namespace = document.getDocumentElement().getNamespaceURI();
NodeList flowDefinitions = document.getDocumentElement().getElementsByTagNameNS(namespace, FACES_FLOW_DEFINITION);
if (flowDefinitions != null && flowDefinitions.getLength() > 0) {
@@ -207,7 +207,7 @@ private void saveFlowDefinition(FacesContext context, URI definingDocumentURI, D
private List getSavedFlowDefinitions(FacesContext context) {
Map appMap = context.getExternalContext().getApplicationMap();
List def = (List) appMap.get(flowDefinitionListKey);
- return null != def ? def : Collections.EMPTY_LIST;
+ return null != def ? def : Collections.emptyList();
}
private void clearSavedFlowDefinitions(FacesContext context) {
diff --git a/impl/src/main/java/com/sun/faces/config/processor/FactoryConfigProcessor.java b/impl/src/main/java/com/sun/faces/config/processor/FactoryConfigProcessor.java
index e8d9f3068b..c448cb370f 100644
--- a/impl/src/main/java/com/sun/faces/config/processor/FactoryConfigProcessor.java
+++ b/impl/src/main/java/com/sun/faces/config/processor/FactoryConfigProcessor.java
@@ -167,12 +167,12 @@ public void process(ServletContext servletContext, FacesContext facesContext, Do
// for this application
AtomicInteger applicationFactoryCount = new AtomicInteger(0);
- for (int i = 0; i < documentInfos.length; i++) {
+ for (DocumentInfo documentInfo : documentInfos) {
if (LOGGER.isLoggable(FINE)) {
- LOGGER.log(FINE, format("Processing factory elements for document: ''{0}''", documentInfos[i].getSourceURI()));
+ LOGGER.log(FINE, format("Processing factory elements for document: ''{0}''", documentInfo.getSourceURI()));
}
- Document document = documentInfos[i].getDocument();
+ Document document = documentInfo.getDocument();
String namespace = document.getDocumentElement().getNamespaceURI();
NodeList factories = document.getDocumentElement().getElementsByTagNameNS(namespace, FACTORY);
if (factories != null && factories.getLength() > 0) {
diff --git a/impl/src/main/java/com/sun/faces/config/processor/NavigationConfigProcessor.java b/impl/src/main/java/com/sun/faces/config/processor/NavigationConfigProcessor.java
index 634be011d8..3235913c73 100644
--- a/impl/src/main/java/com/sun/faces/config/processor/NavigationConfigProcessor.java
+++ b/impl/src/main/java/com/sun/faces/config/processor/NavigationConfigProcessor.java
@@ -311,11 +311,7 @@ private void addNavigationCasesForRule(String fromViewId, List navigationC
// defined navigation mappings.
if (navHandler instanceof ConfigurableNavigationHandler) {
ConfigurableNavigationHandler cnav = (ConfigurableNavigationHandler) navHandler;
- Set cases = cnav.getNavigationCases().get(fromViewId);
- if (cases == null) {
- cases = new LinkedHashSet<>();
- cnav.getNavigationCases().put(fromViewId, cases);
- }
+ Set cases = cnav.getNavigationCases().computeIfAbsent(fromViewId, k -> new LinkedHashSet<>());
cases.add(cnc);
}
associate.addNavigationCase(cnc);
@@ -396,7 +392,7 @@ private Map> processParameters(NodeList children) {
private boolean isIncludeViewParams(Node n) {
- return Boolean.valueOf(getNodeText(n.getAttributes().getNamedItem(INCLUDE_VIEW_PARAMS_ATTRIBUTE)));
+ return Boolean.parseBoolean(getNodeText(n.getAttributes().getNamedItem(INCLUDE_VIEW_PARAMS_ATTRIBUTE)));
}
diff --git a/impl/src/main/java/com/sun/faces/config/processor/ProtectedViewsConfigProcessor.java b/impl/src/main/java/com/sun/faces/config/processor/ProtectedViewsConfigProcessor.java
index ca14ad327d..ff9ed6261d 100644
--- a/impl/src/main/java/com/sun/faces/config/processor/ProtectedViewsConfigProcessor.java
+++ b/impl/src/main/java/com/sun/faces/config/processor/ProtectedViewsConfigProcessor.java
@@ -64,17 +64,17 @@ public ProtectedViewsConfigProcessor() {
@Override
public void process(ServletContext servletContext, FacesContext facesContext, DocumentInfo[] documentInfos) throws Exception {
- for (int i = 0; i < documentInfos.length; i++) {
+ for (DocumentInfo documentInfo : documentInfos) {
if (LOGGER.isLoggable(FINE)) {
- LOGGER.log(FINE, format("Processing protected-views element for document: ''{0}''", documentInfos[i].getSourceURI()));
+ LOGGER.log(FINE, format("Processing protected-views element for document: ''{0}''", documentInfo.getSourceURI()));
}
- Document document = documentInfos[i].getDocument();
+ Document document = documentInfo.getDocument();
String namespace = document.getDocumentElement().getNamespaceURI();
NodeList protectedViews = document.getDocumentElement().getElementsByTagNameNS(namespace, PROTECTED_VIEWS);
if (protectedViews != null && protectedViews.getLength() > 0) {
- processProtectedViews(facesContext, protectedViews, namespace, documentInfos[i]);
+ processProtectedViews(facesContext, protectedViews, namespace, documentInfo);
}
}
diff --git a/impl/src/main/java/com/sun/faces/config/processor/RenderKitConfigProcessor.java b/impl/src/main/java/com/sun/faces/config/processor/RenderKitConfigProcessor.java
index 7202be07ed..d74daa5e68 100644
--- a/impl/src/main/java/com/sun/faces/config/processor/RenderKitConfigProcessor.java
+++ b/impl/src/main/java/com/sun/faces/config/processor/RenderKitConfigProcessor.java
@@ -132,12 +132,12 @@ public void process(ServletContext servletContext, FacesContext facesContext, Do
Map>> behaviorRenderers = new LinkedHashMap<>();
RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
- for (int i = 0; i < documentInfos.length; i++) {
+ for (DocumentInfo documentInfo : documentInfos) {
if (LOGGER.isLoggable(FINE)) {
- LOGGER.log(FINE, format("Processing render-kit elements for document: ''{0}''", documentInfos[i].getSourceURI()));
+ LOGGER.log(FINE, format("Processing render-kit elements for document: ''{0}''", documentInfo.getSourceURI()));
}
- Document document = documentInfos[i].getDocument();
+ Document document = documentInfo.getDocument();
String namespace = document.getDocumentElement().getNamespaceURI();
NodeList renderkits = document.getDocumentElement().getElementsByTagNameNS(namespace, RENDERKIT);
diff --git a/impl/src/main/java/com/sun/faces/config/processor/ResourceLibraryContractsConfigProcessor.java b/impl/src/main/java/com/sun/faces/config/processor/ResourceLibraryContractsConfigProcessor.java
index 20fb25cfde..949e93c570 100644
--- a/impl/src/main/java/com/sun/faces/config/processor/ResourceLibraryContractsConfigProcessor.java
+++ b/impl/src/main/java/com/sun/faces/config/processor/ResourceLibraryContractsConfigProcessor.java
@@ -70,12 +70,12 @@ public ResourceLibraryContractsConfigProcessor() {
public void process(ServletContext servletContext, FacesContext facesContext, DocumentInfo[] documentInfos) throws Exception {
HashMap> map = new HashMap<>();
- for (int i = 0; i < documentInfos.length; i++) {
+ for (DocumentInfo documentInfo : documentInfos) {
if (LOGGER.isLoggable(FINE)) {
- LOGGER.log(FINE, MessageFormat.format("Processing factory elements for document: ''{0}''", documentInfos[i].getSourceURI()));
+ LOGGER.log(FINE, MessageFormat.format("Processing factory elements for document: ''{0}''", documentInfo.getSourceURI()));
}
- Document document = documentInfos[i].getDocument();
+ Document document = documentInfo.getDocument();
String namespace = document.getDocumentElement().getNamespaceURI();
NodeList resourceLibraryContracts = document.getDocumentElement().getElementsByTagNameNS(namespace, RESOURCE_LIBRARY_CONTRACTS);
if (resourceLibraryContracts != null && resourceLibraryContracts.getLength() > 0) {
@@ -125,20 +125,18 @@ private void processResourceLibraryContracts(NodeList resourceLibraryContracts,
if (contracts != null && contracts.getLength() > 0) {
for (int j = 0; j < contracts.getLength(); j++) {
String[] contractStrings = contracts.item(j).getNodeValue().trim().split(",");
- for (int k = 0; k < contractStrings.length; k++) {
- if (!list.contains(contractStrings[k])) {
+ for (String contractString : contractStrings) {
+ if (!list.contains(contractString)) {
if (LOGGER.isLoggable(INFO)) {
- LOGGER.log(INFO, "Added contract: {0} for url-pattern: {1}",
- new Object[] { contractStrings[k], urlPattern });
+ LOGGER.log(INFO, "Added contract: {0} for url-pattern: {1}", new Object[]{contractString, urlPattern});
}
- list.add(contractStrings[k]);
+ list.add(contractString);
} else {
/*
* We found the contract again in the list for the specified url-pattern.
*/
if (LOGGER.isLoggable(INFO)) {
- LOGGER.log(INFO, "Duplicate contract: {0} found for url-pattern: {1}",
- new Object[] { contractStrings[k], urlPattern });
+ LOGGER.log(INFO, "Duplicate contract: {0} found for url-pattern: {1}", new Object[]{contractString, urlPattern});
}
}
}
diff --git a/impl/src/main/java/com/sun/faces/config/processor/ValidatorConfigProcessor.java b/impl/src/main/java/com/sun/faces/config/processor/ValidatorConfigProcessor.java
index ce82134089..17e679e0fa 100644
--- a/impl/src/main/java/com/sun/faces/config/processor/ValidatorConfigProcessor.java
+++ b/impl/src/main/java/com/sun/faces/config/processor/ValidatorConfigProcessor.java
@@ -81,12 +81,12 @@ public void process(ServletContext servletContext, FacesContext facesContext, Do
// via config files take precedence
processAnnotations(facesContext, FacesValidator.class);
- for (int i = 0; i < documentInfos.length; i++) {
+ for (DocumentInfo documentInfo : documentInfos) {
if (LOGGER.isLoggable(FINE)) {
- LOGGER.log(FINE, format("Processing validator elements for document: ''{0}''", documentInfos[i].getSourceURI()));
+ LOGGER.log(FINE, format("Processing validator elements for document: ''{0}''", documentInfo.getSourceURI()));
}
- Document document = documentInfos[i].getDocument();
+ Document document = documentInfo.getDocument();
String namespace = document.getDocumentElement().getNamespaceURI();
NodeList validators = document.getDocumentElement().getElementsByTagNameNS(namespace, VALIDATOR);
diff --git a/impl/src/main/java/com/sun/faces/context/ApplicationMap.java b/impl/src/main/java/com/sun/faces/context/ApplicationMap.java
index aa18cc0ecb..cc98cc0724 100644
--- a/impl/src/main/java/com/sun/faces/context/ApplicationMap.java
+++ b/impl/src/main/java/com/sun/faces/context/ApplicationMap.java
@@ -45,8 +45,8 @@ public Object getContext() {
@Override
public void clear() {
- for (Enumeration e = servletContext.getAttributeNames(); e.hasMoreElements();) {
- servletContext.removeAttribute((String) e.nextElement());
+ for (Enumeration e = servletContext.getAttributeNames(); e.hasMoreElements();) {
+ servletContext.removeAttribute(e.nextElement());
}
}
@@ -91,14 +91,14 @@ public boolean containsKey(Object key) {
@Override
public boolean equals(Object obj) {
- return !(obj == null || !(obj instanceof ApplicationMap)) && super.equals(obj);
+ return obj instanceof ApplicationMap && super.equals(obj);
}
@Override
public int hashCode() {
int hashCode = 7 * servletContext.hashCode();
- for (Iterator i = entrySet().iterator(); i.hasNext();) {
- hashCode += i.next().hashCode();
+ for (Map.Entry stringObjectEntry : entrySet()) {
+ hashCode += stringObjectEntry.hashCode();
}
return hashCode;
}
diff --git a/impl/src/main/java/com/sun/faces/context/BaseContextMap.java b/impl/src/main/java/com/sun/faces/context/BaseContextMap.java
index 972ffce797..8f8b4160e7 100644
--- a/impl/src/main/java/com/sun/faces/context/BaseContextMap.java
+++ b/impl/src/main/java/com/sun/faces/context/BaseContextMap.java
@@ -16,14 +16,7 @@
package com.sun.faces.context;
-import java.util.AbstractCollection;
-import java.util.AbstractMap;
-import java.util.AbstractSet;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
/**
*
@@ -113,7 +106,7 @@ protected boolean removeValue(Object value) {
// ----------------------------------------------------------- Inner Classes
- abstract class BaseSet extends AbstractSet {
+ abstract static class BaseSet extends AbstractSet {
@Override
public int size() {
@@ -163,7 +156,7 @@ class ValueCollection extends AbstractCollection {
@Override
public int size() {
int size = 0;
- for (Iterator i = iterator(); i.hasNext(); size++) {
+ for (Iterator i = iterator(); i.hasNext(); size++) {
i.next();
}
return size;
@@ -180,7 +173,7 @@ public boolean remove(Object o) {
}
}
- abstract class BaseIterator implements Iterator {
+ abstract static class BaseIterator implements Iterator {
protected Enumeration e;
protected String currentKey;
@@ -312,12 +305,8 @@ public boolean equals(Object obj) {
Object inputKey = input.getKey();
Object inputValue = input.getValue();
- if (inputKey == key || inputKey != null && inputKey.equals(key)) {
- if (inputValue == value || inputValue != null && inputValue.equals(value)) {
- return true;
- }
- }
- return false;
+ return Objects.equals(inputKey, key) &&
+ Objects.equals(inputValue, value);
}
}
diff --git a/impl/src/main/java/com/sun/faces/context/FacesContextFactoryImpl.java b/impl/src/main/java/com/sun/faces/context/FacesContextFactoryImpl.java
index c4aff33cf5..2d65ad7b42 100644
--- a/impl/src/main/java/com/sun/faces/context/FacesContextFactoryImpl.java
+++ b/impl/src/main/java/com/sun/faces/context/FacesContextFactoryImpl.java
@@ -91,7 +91,7 @@ private void savePerRequestInitParams(FacesContext context, WebConfiguration web
webConfig.isOptionEnabled(ViewRootPhaseListenerQueuesException) ? Boolean.TRUE : Boolean.FALSE);
attrs.put(EnableValidateWholeBean.getQualifiedName(), webConfig.isOptionEnabled(EnableValidateWholeBean) ? Boolean.TRUE : Boolean.FALSE);
- String facesConfigVersion = "" + appMap.get(RIConstants.FACES_CONFIG_VERSION);
+ String facesConfigVersion = String.valueOf(appMap.get(RIConstants.FACES_CONFIG_VERSION));
attrs.put(RIConstants.FACES_CONFIG_VERSION, facesConfigVersion);
}
diff --git a/impl/src/main/java/com/sun/faces/context/InitParameterMap.java b/impl/src/main/java/com/sun/faces/context/InitParameterMap.java
index 860527d90f..7c41a21cd6 100644
--- a/impl/src/main/java/com/sun/faces/context/InitParameterMap.java
+++ b/impl/src/main/java/com/sun/faces/context/InitParameterMap.java
@@ -76,8 +76,8 @@ public boolean equals(Object obj) {
@Override
public int hashCode() {
int hashCode = 7 * servletContext.hashCode();
- for (Iterator i = entrySet().iterator(); i.hasNext();) {
- hashCode += i.next().hashCode();
+ for (Map.Entry stringStringEntry : entrySet()) {
+ hashCode += stringStringEntry.hashCode();
}
return hashCode;
}
diff --git a/impl/src/main/java/com/sun/faces/context/RequestCookieMap.java b/impl/src/main/java/com/sun/faces/context/RequestCookieMap.java
index b8ef82ec05..545fffd24f 100644
--- a/impl/src/main/java/com/sun/faces/context/RequestCookieMap.java
+++ b/impl/src/main/java/com/sun/faces/context/RequestCookieMap.java
@@ -88,8 +88,8 @@ public boolean equals(Object obj) {
@Override
public int hashCode() {
int hashCode = 7 * request.hashCode();
- for (Iterator i = entrySet().iterator(); i.hasNext();) {
- hashCode += i.next().hashCode();
+ for (Map.Entry stringObjectEntry : entrySet()) {
+ hashCode += stringObjectEntry.hashCode();
}
return hashCode;
}
diff --git a/impl/src/main/java/com/sun/faces/context/RequestHeaderMap.java b/impl/src/main/java/com/sun/faces/context/RequestHeaderMap.java
index 14c2b2aa79..7173c9da14 100644
--- a/impl/src/main/java/com/sun/faces/context/RequestHeaderMap.java
+++ b/impl/src/main/java/com/sun/faces/context/RequestHeaderMap.java
@@ -76,8 +76,8 @@ public boolean equals(Object obj) {
@Override
public int hashCode() {
int hashCode = 7 * request.hashCode();
- for (Iterator i = entrySet().iterator(); i.hasNext();) {
- hashCode += i.next().hashCode();
+ for (Map.Entry stringStringEntry : entrySet()) {
+ hashCode += stringStringEntry.hashCode();
}
return hashCode;
}
diff --git a/impl/src/main/java/com/sun/faces/context/RequestHeaderValuesMap.java b/impl/src/main/java/com/sun/faces/context/RequestHeaderValuesMap.java
index 99013b46ed..bb5b9507c1 100644
--- a/impl/src/main/java/com/sun/faces/context/RequestHeaderValuesMap.java
+++ b/impl/src/main/java/com/sun/faces/context/RequestHeaderValuesMap.java
@@ -54,9 +54,9 @@ public String[] get(Object key) {
Util.notNull("key", key);
List valuesList = new ArrayList<>();
- Enumeration valuesEnum = request.getHeaders(key.toString());
+ Enumeration valuesEnum = request.getHeaders(key.toString());
while (valuesEnum.hasMoreElements()) {
- valuesList.add((String) valuesEnum.nextElement());
+ valuesList.add(valuesEnum.nextElement());
}
return valuesList.toArray(new String[valuesList.size()]);
diff --git a/impl/src/main/java/com/sun/faces/context/RequestMap.java b/impl/src/main/java/com/sun/faces/context/RequestMap.java
index 9a91d96091..920c545fdd 100644
--- a/impl/src/main/java/com/sun/faces/context/RequestMap.java
+++ b/impl/src/main/java/com/sun/faces/context/RequestMap.java
@@ -41,8 +41,8 @@ public RequestMap(ServletRequest request) {
@Override
public void clear() {
- for (Enumeration e = request.getAttributeNames(); e.hasMoreElements();) {
- request.removeAttribute((String) e.nextElement());
+ for (Enumeration e = request.getAttributeNames(); e.hasMoreElements();) {
+ request.removeAttribute(e.nextElement());
}
}
@@ -87,14 +87,14 @@ public boolean containsKey(Object key) {
@Override
public boolean equals(Object obj) {
- return !(obj == null || !(obj instanceof RequestMap)) && super.equals(obj);
+ return obj instanceof RequestMap && super.equals(obj);
}
@Override
public int hashCode() {
int hashCode = 7 * request.hashCode();
- for (Iterator i = entrySet().iterator(); i.hasNext();) {
- hashCode += i.next().hashCode();
+ for (Map.Entry stringObjectEntry : entrySet()) {
+ hashCode += stringObjectEntry.hashCode();
}
return hashCode;
}
diff --git a/impl/src/main/java/com/sun/faces/context/RequestParameterMap.java b/impl/src/main/java/com/sun/faces/context/RequestParameterMap.java
index 309a10cc94..6000c855ed 100644
--- a/impl/src/main/java/com/sun/faces/context/RequestParameterMap.java
+++ b/impl/src/main/java/com/sun/faces/context/RequestParameterMap.java
@@ -107,8 +107,8 @@ public boolean equals(Object obj) {
@Override
public int hashCode() {
int hashCode = 7 * request.hashCode();
- for (Iterator i = entrySet().iterator(); i.hasNext();) {
- hashCode += i.next().hashCode();
+ for (Map.Entry stringStringEntry : entrySet()) {
+ hashCode += stringStringEntry.hashCode();
}
return hashCode;
}
diff --git a/impl/src/main/java/com/sun/faces/context/SessionMap.java b/impl/src/main/java/com/sun/faces/context/SessionMap.java
index 9ccf3b3c8b..29a5972a86 100644
--- a/impl/src/main/java/com/sun/faces/context/SessionMap.java
+++ b/impl/src/main/java/com/sun/faces/context/SessionMap.java
@@ -54,8 +54,8 @@ public SessionMap(HttpServletRequest request, ProjectStage stage) {
public void clear() {
HttpSession session = getSession(false);
if (session != null) {
- for (Enumeration e = session.getAttributeNames(); e.hasMoreElements();) {
- String name = (String) e.nextElement();
+ for (Enumeration e = session.getAttributeNames(); e.hasMoreElements();) {
+ String name = e.nextElement();
session.removeAttribute(name);
}
}
@@ -133,7 +133,7 @@ public boolean containsKey(Object key) {
@Override
public boolean equals(Object obj) {
- return !(obj == null || !(obj instanceof SessionMap)) && super.equals(obj);
+ return obj instanceof SessionMap && super.equals(obj);
}
@Override
@@ -141,8 +141,8 @@ public int hashCode() {
HttpSession session = getSession(false);
int hashCode = 7 * (session != null ? session.hashCode() : super.hashCode());
if (session != null) {
- for (Iterator i = entrySet().iterator(); i.hasNext();) {
- hashCode += i.next().hashCode();
+ for (Map.Entry stringObjectEntry : entrySet()) {
+ hashCode += stringObjectEntry.hashCode();
}
}
return hashCode;
@@ -156,8 +156,7 @@ protected Iterator> getEntryIterator() {
if (session != null) {
return new EntryIterator(session.getAttributeNames());
} else {
- Map empty = Collections.emptyMap();
- return empty.entrySet().iterator();
+ return Collections.emptyIterator();
}
}
@@ -167,8 +166,7 @@ protected Iterator getKeyIterator() {
if (session != null) {
return new KeyIterator(session.getAttributeNames());
} else {
- Map empty = Collections.emptyMap();
- return empty.keySet().iterator();
+ return Collections.emptyIterator();
}
}
@@ -178,8 +176,7 @@ protected Iterator
*/
- public static final List VALUES = unmodifiableList(asList(values));
+ public static final List VALUES = List.of(values);
- private static Map _MODIFIABLE_MAP = new HashMap<>(4, 1.0f);
+ private static final Map _MODIFIABLE_MAP = new HashMap<>(4, 1.0f);
static {
- for (int i = 0, len = values.length; i < len; i++) {
- _MODIFIABLE_MAP.put(values[i].severityName, values[i]);
+ for (Severity value : values) {
+ _MODIFIABLE_MAP.put(value.severityName, value);
}
}
@@ -150,7 +148,7 @@ public class FacesMessage implements Serializable {
* Immutable Map of valid {@link jakarta.faces.application.FacesMessage.Severity} instances, keyed by name.
*
*/
- public final static Map VALUES_MAP = unmodifiableMap(_MODIFIABLE_MAP);
+ public final static Map VALUES_MAP = unmodifiableMap(_MODIFIABLE_MAP);
private static final long serialVersionUID = -1180773928220076822L;
@@ -377,7 +375,7 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE
* Class used to represent message severity levels in a typesafe enumeration.
*
*/
- public static class Severity implements Comparable {
+ public static class Severity implements Comparable {
// ------------------------------------------------------- Constructors
@@ -415,11 +413,11 @@ private Severity(String newSeverityName) {
* object.
*
*
- * @param other The other object to be compared to
+ * @param severity The other object to be compared to
*/
@Override
- public int compareTo(Object other) {
- return ordinal - ((Severity) other).ordinal;
+ public int compareTo(Severity severity) {
+ return ordinal - severity.ordinal;
}
/**
@@ -441,10 +439,10 @@ public int getOrdinal() {
@Override
public String toString() {
if (severityName == null) {
- return String.valueOf(ordinal);
+ return Integer.toString(ordinal);
}
- return String.valueOf(severityName) + ' ' + ordinal;
+ return severityName + ' ' + ordinal;
}
// --------------------------------------------------- Static Variables
diff --git a/impl/src/main/java/jakarta/faces/application/ResourceHandler.java b/impl/src/main/java/jakarta/faces/application/ResourceHandler.java
index 9acd56e630..14ad1a6d29 100644
--- a/impl/src/main/java/jakarta/faces/application/ResourceHandler.java
+++ b/impl/src/main/java/jakarta/faces/application/ResourceHandler.java
@@ -722,7 +722,7 @@ public boolean isResourceURL(String url) {
*/
@SuppressWarnings("unchecked")
public void markResourceRendered(FacesContext context, String resourceName, String libraryName) {
- String resourceIdentifier = libraryName + ":" + resourceName;
+ String resourceIdentifier = libraryName + ':' + resourceName;
Set resourceIdentifiers = (Set) context.getAttributes().computeIfAbsent(RESOURCE_IDENTIFIER, k -> new HashSet<>());
resourceIdentifiers.add(resourceIdentifier);
}
@@ -742,7 +742,7 @@ public void markResourceRendered(FacesContext context, String resourceName, Stri
*/
@SuppressWarnings("unchecked")
public boolean isResourceRendered(FacesContext context, String resourceName, String libraryName) {
- String resourceIdentifier = libraryName + ":" + resourceName;
+ String resourceIdentifier = libraryName + ':' + resourceName;
Set resourceIdentifiers = (Set) context.getAttributes().get(RESOURCE_IDENTIFIER);
return resourceIdentifiers != null && resourceIdentifiers.contains(resourceIdentifier);
}
diff --git a/impl/src/main/java/jakarta/faces/component/AttachedObjectListHolder.java b/impl/src/main/java/jakarta/faces/component/AttachedObjectListHolder.java
index c15d76fcac..18363d9e72 100644
--- a/impl/src/main/java/jakarta/faces/component/AttachedObjectListHolder.java
+++ b/impl/src/main/java/jakarta/faces/component/AttachedObjectListHolder.java
@@ -133,8 +133,8 @@ public void restoreState(FacesContext context, Object state) {
this.attachedObjects = new ArrayList<>(2);
}
- for (int i = 0, len = attachedObjects.length; i < len; i++) {
- T restored = (T) ((StateHolderSaver) attachedObjects[i]).restore(context);
+ for (Object attachedObject : attachedObjects) {
+ T restored = (T) ((StateHolderSaver) attachedObject).restore(context);
if (restored != null) {
add(restored);
}
diff --git a/impl/src/main/java/jakarta/faces/component/UIOutput.java b/impl/src/main/java/jakarta/faces/component/UIOutput.java
index bb5be933bd..6935b85568 100644
--- a/impl/src/main/java/jakarta/faces/component/UIOutput.java
+++ b/impl/src/main/java/jakarta/faces/component/UIOutput.java
@@ -173,7 +173,7 @@ public void clearInitialState() {
super.clearInitialState();
Converter> c = getConverter();
- if (c != null && c instanceof PartialStateHolder) {
+ if (c instanceof PartialStateHolder) {
((PartialStateHolder) c).clearInitialState();
}
}
diff --git a/impl/src/main/java/jakarta/faces/component/UISelectBoolean.java b/impl/src/main/java/jakarta/faces/component/UISelectBoolean.java
index 8c6e8e155d..ac8ac660d6 100644
--- a/impl/src/main/java/jakarta/faces/component/UISelectBoolean.java
+++ b/impl/src/main/java/jakarta/faces/component/UISelectBoolean.java
@@ -76,12 +76,8 @@ public String getFamily() {
* @return true if selected, false otherwise.
*/
public boolean isSelected() {
- Boolean value = (Boolean) getValue();
- if (value != null) {
- return value.booleanValue();
- }
- return false;
+ return Boolean.TRUE.equals(getValue());
}
/**
diff --git a/impl/src/main/java/jakarta/faces/component/behavior/AjaxBehavior.java b/impl/src/main/java/jakarta/faces/component/behavior/AjaxBehavior.java
index e7b1b80186..ddd50085c2 100644
--- a/impl/src/main/java/jakarta/faces/component/behavior/AjaxBehavior.java
+++ b/impl/src/main/java/jakarta/faces/component/behavior/AjaxBehavior.java
@@ -555,7 +555,7 @@ private static Object saveBindings(FacesContext context, Map restoreBindings(FacesContext context
if (state == null) {
return null;
}
- Object values[] = (Object[]) state;
- String names[] = (String[]) values[0];
- Object states[] = (Object[]) values[1];
+ Object[] values = (Object[]) state;
+ String[] names = (String[]) values[0];
+ Object[] states = (Object[]) values[1];
Map bindings = new HashMap<>(names.length);
for (int i = 0; i < names.length; i++) {
bindings.put(names[i], (ValueExpression) UIComponentBase.restoreAttachedState(context, states[i]));
@@ -615,7 +615,7 @@ private static List restoreList(String propertyName, Object state) {
if (state instanceof String) {
list = toSingletonList(propertyName, (String) state);
} else if (state instanceof String[]) {
- list = Collections.unmodifiableList(Arrays.asList((String[]) state));
+ list = List.of((String[]) state);
}
return list;
@@ -730,8 +730,8 @@ private static List toList(String propertyName, ValueExpression expressi
// we care about removing duplicates. However, the
// presence of duplicates does not real harm. They will
// be consolidated during the partial view traversal. So,
- // just create an list - garbage in, garbage out.
- return Collections.unmodifiableList(Arrays.asList(values));
+ // just create a list - garbage in, garbage out.
+ return List.of(values);
}
// RELEASE_PENDING i18n ;
@@ -747,29 +747,25 @@ private static List toSingletonList(String propertyName, String value) {
if (value.charAt(0) == '@') {
// These are very common, so we use shared copies
// of these collections instead of re-creating.
-
- if (ALL.equals(value)) {
- return ALL_LIST;
- } else if (FORM.equals(value)) {
- return FORM_LIST;
- } else if (THIS.equals(value)) {
- return THIS_LIST;
- } else if (NONE.equals(value)) {
- return NONE_LIST;
+ switch (value) {
+ case ALL: return ALL_LIST;
+ case FORM: return FORM_LIST;
+ case THIS: return THIS_LIST;
+ case NONE: return NONE_LIST;
}
}
- return Collections.singletonList(value);
+ return List.of(value);
}
// Makes a defensive copy of the collection, converting to a List
// (to make state saving a bit easier).
- private List copyToList(Collection collection) {
+ private static List copyToList(Collection collection) {
if (collection == null || collection.isEmpty()) {
return null;
}
- return Collections.unmodifiableList(new ArrayList<>(collection));
+ return List.copyOf(collection);
}
// Property name constants
@@ -783,18 +779,18 @@ private List copyToList(Collection collection) {
private static final String DELAY = "delay";
// Id keyword constants
- private static String ALL = "@all";
- private static String FORM = "@form";
- private static String THIS = "@this";
- private static String NONE = "@none";
+ private static final String ALL = "@all";
+ private static final String FORM = "@form";
+ private static final String THIS = "@this";
+ private static final String NONE = "@none";
// Shared execute/render collections
- private static List ALL_LIST = Collections.singletonList("@all");
- private static List FORM_LIST = Collections.singletonList("@form");
- private static List THIS_LIST = Collections.singletonList("@this");
- private static List NONE_LIST = Collections.singletonList("@none");
+ private static final List ALL_LIST = List.of(ALL);
+ private static final List FORM_LIST = List.of(FORM);
+ private static final List THIS_LIST = List.of(THIS);
+ private static final List NONE_LIST = List.of(NONE);
// Pattern used for execute/render string splitting
- private static Pattern SPLIT_PATTERN = Pattern.compile(" ");
+ private static final Pattern SPLIT_PATTERN = Pattern.compile(" ");
}
diff --git a/impl/src/main/java/jakarta/faces/model/ArrayDataModel.java b/impl/src/main/java/jakarta/faces/model/ArrayDataModel.java
index a858a39da1..d3d8ddfa47 100644
--- a/impl/src/main/java/jakarta/faces/model/ArrayDataModel.java
+++ b/impl/src/main/java/jakarta/faces/model/ArrayDataModel.java
@@ -55,7 +55,7 @@ public ArrayDataModel(E[] array) {
// ------------------------------------------------------ Instance Variables
// The array we are wrapping
- private Object array[];
+ private Object[] array;
// The current row index (zero relative)
private int index = -1;
@@ -74,13 +74,7 @@ public ArrayDataModel(E[] array) {
@Override
public boolean isRowAvailable() {
- if (array == null) {
- return false;
- } else if (index >= 0 && index < array.length) {
- return true;
- } else {
- return false;
- }
+ return array != null && index >= 0 && index < array.length;
}
@@ -158,9 +152,9 @@ public void setRowIndex(int rowIndex) {
}
DataModelEvent event = new DataModelEvent(this, index, rowData);
int n = listeners.length;
- for (int i = 0; i < n; i++) {
- if (null != listeners[i]) {
- listeners[i].rowSelected(event);
+ for (DataModelListener listener : listeners) {
+ if (null != listener) {
+ listener.rowSelected(event);
}
}
}
diff --git a/impl/src/main/java/jakarta/faces/model/CollectionDataModel.java b/impl/src/main/java/jakarta/faces/model/CollectionDataModel.java
index 01cb479a21..6275bf3862 100644
--- a/impl/src/main/java/jakarta/faces/model/CollectionDataModel.java
+++ b/impl/src/main/java/jakarta/faces/model/CollectionDataModel.java
@@ -76,13 +76,7 @@ public CollectionDataModel(Collection collection) {
@Override
public boolean isRowAvailable() {
- if (arrayFromInner == null) {
- return false;
- } else if (index >= 0 && index < arrayFromInner.length) {
- return true;
- } else {
- return false;
- }
+ return arrayFromInner != null && index >= 0 && index < arrayFromInner.length;
}
/**
@@ -158,9 +152,9 @@ public void setRowIndex(int rowIndex) {
}
DataModelEvent event = new DataModelEvent(this, index, rowData);
int n = listeners.length;
- for (int i = 0; i < n; i++) {
- if (null != listeners[i]) {
- listeners[i].rowSelected(event);
+ for (DataModelListener listener : listeners) {
+ if (null != listener) {
+ listener.rowSelected(event);
}
}
}
diff --git a/impl/src/main/java/jakarta/faces/model/ListDataModel.java b/impl/src/main/java/jakarta/faces/model/ListDataModel.java
index 4958f72028..ab97bc8b67 100644
--- a/impl/src/main/java/jakarta/faces/model/ListDataModel.java
+++ b/impl/src/main/java/jakarta/faces/model/ListDataModel.java
@@ -60,7 +60,7 @@ public ListDataModel(List list) {
private int index = -1;
// The list we are wrapping
- private List list;
+ private List list;
// -------------------------------------------------------------- Properties
@@ -76,13 +76,7 @@ public ListDataModel(List list) {
@Override
public boolean isRowAvailable() {
- if (list == null) {
- return false;
- } else if (index >= 0 && index < list.size()) {
- return true;
- } else {
- return false;
- }
+ return list != null && index >= 0 && index < list.size();
}
@@ -158,10 +152,9 @@ public void setRowIndex(int rowIndex) {
rowData = getRowData();
}
DataModelEvent event = new DataModelEvent(this, index, rowData);
- int n = listeners.length;
- for (int i = 0; i < n; i++) {
- if (null != listeners[i]) {
- listeners[i].rowSelected(event);
+ for (DataModelListener listener : listeners) {
+ if (null != listener) {
+ listener.rowSelected(event);
}
}
}
@@ -185,7 +178,7 @@ public void setWrappedData(Object data) {
list = null;
setRowIndex(-1);
} else {
- list = (List) data;
+ list = (List) data;
index = -1;
setRowIndex(0);
}
diff --git a/impl/src/main/java/jakarta/faces/model/ScalarDataModel.java b/impl/src/main/java/jakarta/faces/model/ScalarDataModel.java
index 6f9854f5c2..1be762b9bb 100644
--- a/impl/src/main/java/jakarta/faces/model/ScalarDataModel.java
+++ b/impl/src/main/java/jakarta/faces/model/ScalarDataModel.java
@@ -73,13 +73,7 @@ public ScalarDataModel(E scalar) {
@Override
public boolean isRowAvailable() {
- if (scalar == null) {
- return false;
- } else if (index == 0) {
- return true;
- } else {
- return false;
- }
+ return scalar != null && index == 0;
}
@@ -116,7 +110,6 @@ public E getRowData() {
} else if (!isRowAvailable()) {
throw new NoRowAvailableException();
} else {
- // noinspection unchecked
return scalar;
}
@@ -154,10 +147,9 @@ public void setRowIndex(int rowIndex) {
rowData = getRowData();
}
DataModelEvent event = new DataModelEvent(this, index, rowData);
- int n = listeners.length;
- for (int i = 0; i < n; i++) {
- if (null != listeners[i]) {
- listeners[i].rowSelected(event);
+ for (DataModelListener listener : listeners) {
+ if (null != listener) {
+ listener.rowSelected(event);
}
}
}