From 6d7d6674d324e2157a8e06af01d563bd5da6333b Mon Sep 17 00:00:00 2001 From: pizzi80 Date: Tue, 20 Jun 2023 01:53:35 +0200 Subject: [PATCH 1/2] + final on effective final fields + Java style array declaration instead of C-style Signed-off-by: pizzi80 --- .../application/ApplicationAssociate.java | 29 +++----- .../application/ApplicationStateInfo.java | 2 +- .../application/ByteArrayWebOutputStream.java | 2 +- .../ConverterPropertyEditorFactory.java | 20 ++--- .../faces/application/NamedEventManager.java | 10 +-- .../sun/faces/application/WebPrintWriter.java | 4 +- .../application/WebappLifecycleListener.java | 2 +- .../annotation/AnnotationManager.java | 8 +- .../application/annotation/EJBHandler.java | 8 +- .../annotation/FacesComponentUsage.java | 4 +- .../annotation/ListenerForHandler.java | 14 ++-- .../annotation/PersistenceContextHandler.java | 8 +- .../annotation/PersistenceUnitHandler.java | 8 +- .../annotation/ResourceDependencyHandler.java | 4 +- .../annotation/ResourceHandler.java | 8 +- .../annotation/WebServiceRefHandler.java | 8 +- .../application/applicationimpl/Events.java | 6 +- .../applicationimpl/ExpressionLanguage.java | 4 +- .../applicationimpl/InstanceFactory.java | 16 ++-- .../applicationimpl/SearchExpression.java | 2 +- .../events/ComponentSystemEventHelper.java | 2 +- .../applicationimpl/events/EventInfo.java | 8 +- .../events/SystemEventInfo.java | 2 +- .../resource/ClasspathResourceHelper.java | 4 +- .../resource/FaceletLibraryInfo.java | 2 +- .../resource/FaceletResourceInfo.java | 2 +- .../application/resource/LibraryInfo.java | 6 +- .../application/resource/ResourceCache.java | 2 +- .../resource/ResourceHandlerImpl.java | 8 +- .../application/resource/ResourceHelper.java | 10 +-- .../application/resource/ResourceManager.java | 10 +-- .../application/resource/VersionInfo.java | 15 ++-- .../resource/WebappResourceHelper.java | 4 +- .../view/FaceletViewHandlingStrategy.java | 2 +- .../application/view/FormOmittedChecker.java | 2 +- .../application/view/MultiViewHandler.java | 12 +-- .../application/view/ViewMetadataImpl.java | 2 +- .../application/view/ViewScopeManager.java | 4 +- .../view/WriteBehindStateWriter.java | 14 ++-- .../java/com/sun/faces/cdi/CdiExtension.java | 2 +- .../java/com/sun/faces/cdi/CdiProducer.java | 2 +- .../CompositeComponentStackManager.java | 10 +-- .../validator/ComponentValidators.java | 22 +++--- .../component/visit/FullVisitContext.java | 4 +- .../com/sun/faces/config/ConfigManager.java | 17 ++--- .../sun/faces/config/ConfigureListener.java | 6 +- .../faces/config/FaceletsConfiguration.java | 6 +- .../sun/faces/config/InitFacesContext.java | 2 +- .../java/com/sun/faces/config/Verifier.java | 2 +- .../sun/faces/config/WebConfiguration.java | 73 +++++++++---------- .../faces/config/manager/FacesConfigInfo.java | 6 +- .../documents/DocumentOrderingWrapper.java | 29 +++----- .../tasks/FindAnnotatedConfigClasses.java | 8 +- .../tasks/FindConfigResourceURIsTask.java | 8 +- .../tasks/ParseConfigResourceToDOMTask.java | 6 +- .../processor/ConverterConfigProcessor.java | 6 +- .../FacesConfigExtensionProcessor.java | 8 +- .../processor/LifecycleConfigProcessor.java | 8 +- .../context/AjaxNoAjaxExceptionHandler.java | 2 +- .../faces/context/ExceptionHandlerImpl.java | 6 +- .../faces/context/PartialViewContextImpl.java | 10 +-- .../faces/context/StringArrayValuesMap.java | 13 ++-- .../com/sun/faces/context/flash/ELFlash.java | 4 +- ...ompositeComponentAttributesELResolver.java | 10 +-- .../java/com/sun/faces/el/ELContextImpl.java | 6 +- .../sun/faces/renderkit/AttributeManager.java | 2 +- .../com/sun/faces/util/ComponentStruct.java | 4 +- .../java/com/sun/faces/util/FacesLogger.java | 2 +- .../main/java/com/sun/faces/util/LRUMap.java | 2 +- .../com/sun/faces/util/MessageFactory.java | 6 +- .../sun/faces/util/MetadataWrapperMap.java | 4 +- .../java/com/sun/faces/util/ScopedRunner.java | 6 +- .../vendor/WebContainerInjectionProvider.java | 4 +- .../faces/CurrentThreadToServletContext.java | 9 ++- .../application/NavigationCaseWrapper.java | 2 +- .../application/StateManagerWrapper.java | 2 +- .../faces/component/ComponentStateHelper.java | 8 +- .../faces/component/MessageFactory.java | 4 +- .../faces/component/SelectItemsIterator.java | 22 +++--- .../faces/component/UIComponentBase.java | 2 +- .../java/jakarta/faces/component/UIData.java | 4 +- .../faces/component/UINamingContainer.java | 2 +- .../jakarta/faces/component/UIViewAction.java | 4 +- .../faces/component/UIViewParameter.java | 6 +- .../faces/component/UpdateModelException.java | 2 +- .../behavior/ClientBehaviorContext.java | 32 +++----- .../faces/component/visit/VisitContext.java | 2 +- .../jakarta/faces/context/FacesContext.java | 33 ++++----- .../jakarta/faces/context/ResponseWriter.java | 2 +- .../event/ExceptionQueuedEventContext.java | 13 ++-- .../java/jakarta/faces/event/PhaseEvent.java | 4 +- .../jakarta/faces/event/ScopeContext.java | 4 +- .../java/jakarta/faces/model/DataModel.java | 2 +- .../jakarta/faces/model/SelectItemGroup.java | 4 +- .../jakarta/faces/webapp/FacesServlet.java | 12 ++- .../jakarta/faces/webapp/MessageFactory.java | 4 +- 96 files changed, 357 insertions(+), 406 deletions(-) diff --git a/impl/src/main/java/com/sun/faces/application/ApplicationAssociate.java b/impl/src/main/java/com/sun/faces/application/ApplicationAssociate.java index 8b9f6b1440..e08430df88 100644 --- a/impl/src/main/java/com/sun/faces/application/ApplicationAssociate.java +++ b/impl/src/main/java/com/sun/faces/application/ApplicationAssociate.java @@ -119,14 +119,14 @@ public class ApplicationAssociate { private final static String FacesComponentJcpNamespace = "http://xmlns.jcp.org/jsf/component"; - private ApplicationImpl applicationImpl; + private final ApplicationImpl applicationImpl; /** * Overall Map containing from-view-id key and Set of NavigationCase objects for * that key; The from-view-id strings in this map will be stored as specified in the configuration file - * some of them will have a trailing asterisk "*" signifying wild card, and some may be specified as an asterisk "*". */ - private Map> navigationMap; + private final Map> navigationMap; /* * The FacesComponentTagLibrary uses the information in this map to help it fabricate tag handlers for components @@ -139,43 +139,38 @@ public class ApplicationAssociate { private static final String ASSOCIATE_KEY = RIConstants.FACES_PREFIX + "ApplicationAssociate"; - private static ThreadLocal instance = new ThreadLocal<>() { - @Override - protected ApplicationAssociate initialValue() { - return null; - } - }; + private static final ThreadLocal instance = ThreadLocal.withInitial(() -> null); private List elResolversFromFacesConfig; private ExpressionFactory expressionFactory; - private InjectionProvider injectionProvider; + private final InjectionProvider injectionProvider; private ResourceCache resourceCache; private String contextName; private boolean requestServiced; private boolean errorPagePresent; - private AnnotationManager annotationManager; - private boolean devModeEnabled; + private final AnnotationManager annotationManager; + private final boolean devModeEnabled; private Compiler compiler; private DefaultFaceletFactory faceletFactory; private ResourceManager resourceManager; - private ApplicationStateInfo applicationStateInfo; + private final ApplicationStateInfo applicationStateInfo; - private PropertyEditorHelper propertyEditorHelper; + private final PropertyEditorHelper propertyEditorHelper; - private NamedEventManager namedEventManager; + private final NamedEventManager namedEventManager; - private WebConfiguration webConfig; + private final WebConfiguration webConfig; private FlowHandler flowHandler; private SearchExpressionHandler searchExpressionHandler; - private Map definingDocumentIdsToTruncatedJarUrls; + private final Map definingDocumentIdsToTruncatedJarUrls; - private long timeOfInstantiation; + private final long timeOfInstantiation; private Map> resourceLibraryContracts; diff --git a/impl/src/main/java/com/sun/faces/application/ApplicationStateInfo.java b/impl/src/main/java/com/sun/faces/application/ApplicationStateInfo.java index b34e108231..50c4d573e6 100644 --- a/impl/src/main/java/com/sun/faces/application/ApplicationStateInfo.java +++ b/impl/src/main/java/com/sun/faces/application/ApplicationStateInfo.java @@ -32,7 +32,7 @@ */ public class ApplicationStateInfo { - private boolean partialStateSaving; + private final boolean partialStateSaving; private Set fullStateViewIds; // ------------------------------------------------------------ Constructors diff --git a/impl/src/main/java/com/sun/faces/application/ByteArrayWebOutputStream.java b/impl/src/main/java/com/sun/faces/application/ByteArrayWebOutputStream.java index 739834efb5..87bdc36ebe 100644 --- a/impl/src/main/java/com/sun/faces/application/ByteArrayWebOutputStream.java +++ b/impl/src/main/java/com/sun/faces/application/ByteArrayWebOutputStream.java @@ -45,7 +45,7 @@ class ByteArrayWebOutputStream extends ServletOutputStream { // Log instance for this class private static final Logger LOGGER = FacesLogger.APPLICATION.getLogger(); - private DirectByteArrayOutputStream baos; + private final DirectByteArrayOutputStream baos; private boolean committed; public ByteArrayWebOutputStream() { diff --git a/impl/src/main/java/com/sun/faces/application/ConverterPropertyEditorFactory.java b/impl/src/main/java/com/sun/faces/application/ConverterPropertyEditorFactory.java index 660e566abb..f5a824a2e6 100644 --- a/impl/src/main/java/com/sun/faces/application/ConverterPropertyEditorFactory.java +++ b/impl/src/main/java/com/sun/faces/application/ConverterPropertyEditorFactory.java @@ -25,6 +25,7 @@ import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.lang.ref.WeakReference; +import java.nio.charset.StandardCharsets; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.HashMap; @@ -118,7 +119,7 @@ public int compareTo(Utf8InfoReplacement rhs) { // The source template class on which to base the definition of the new // PropertyEditor classes. - private Class templateClass; + private final Class templateClass; // The bytes that define the source template class. private byte[] templateBytes; // The constant_pool_count from the template class bytecodes. @@ -341,7 +342,7 @@ private byte[] replaceInTemplate(Utf8InfoReplacement... replacements) { */ public byte[] generateClassBytesFor(String newClassName, String targetClassName) { return replaceInTemplate(new Utf8InfoReplacement(classNameConstant, newClassName), - new Utf8InfoReplacement(classNameRefConstant, new StringBuilder(32).append('L').append(newClassName).append(';').toString()), + new Utf8InfoReplacement(classNameRefConstant, 'L' + newClassName + ';'), new Utf8InfoReplacement(targetClassConstant, targetClassName)); } } @@ -361,9 +362,9 @@ public byte[] generateClassBytesFor(String newClassName, String targetClassName) */ private class DisposableClassLoader extends ClassLoader { // The class loader which loaded the target class. - private ClassLoader targetLoader; + private final ClassLoader targetLoader; // The class loader which loaded the base class - private ClassLoader myLoader; + private final ClassLoader myLoader; public DisposableClassLoader(ClassLoader targetLoader) { super(targetLoader); @@ -439,7 +440,7 @@ protected Class findClass(String className) throws ClassNotFoundException { private static final Pattern MultipleUnderscorePattern = Pattern.compile("_(_+)"); private static ConverterPropertyEditorFactory defaultInstance; // Template information extracted from the source template class. - private ClassTemplateInfo templateInfo; + private final ClassTemplateInfo templateInfo; // Cache of DisposableClassLoaders keyed on the class loader of the target. private Map> classLoaderCache; @@ -543,14 +544,7 @@ private static String getVMClassName(Class c) { */ private static byte[] getUtf8InfoBytes(String text) { byte[] utf8; - try { - utf8 = text.getBytes("UTF-8"); - } catch (UnsupportedEncodingException e) { - // The DM_DEFAULT_ENCODING warning is acceptable here - // because we explicitly *want* to use the Java runtime's - // default encoding. - utf8 = text.getBytes(); - } + utf8 = text.getBytes(StandardCharsets.UTF_8); byte[] info = new byte[utf8.length + 3]; info[0] = 1; info[1] = (byte) (utf8.length >> 8 & 0xff); diff --git a/impl/src/main/java/com/sun/faces/application/NamedEventManager.java b/impl/src/main/java/com/sun/faces/application/NamedEventManager.java index 1dea5a5230..7d28fdef9d 100644 --- a/impl/src/main/java/com/sun/faces/application/NamedEventManager.java +++ b/impl/src/main/java/com/sun/faces/application/NamedEventManager.java @@ -38,8 +38,8 @@ */ public class NamedEventManager { - private Map> namedEvents = new ConcurrentHashMap<>(); - private Map>> duplicateNames = new ConcurrentHashMap<>(); + private final Map> namedEvents = new ConcurrentHashMap<>(); + private final Map>> duplicateNames = new ConcurrentHashMap<>(); public NamedEventManager() { namedEvents.put("jakarta.faces.event.PreRenderComponent", PreRenderComponentEvent.class); @@ -81,12 +81,8 @@ public Class getNamedEvent(String name) { public void addDuplicateName(String name, Class event) { Class registeredEvent = namedEvents.remove(name); - Set> events = duplicateNames.get(name); + Set> events = duplicateNames.computeIfAbsent(name, k -> new HashSet<>()); - if (events == null) { - events = new HashSet<>(); - duplicateNames.put(name, events); - } events.add(event); if (registeredEvent != null) { diff --git a/impl/src/main/java/com/sun/faces/application/WebPrintWriter.java b/impl/src/main/java/com/sun/faces/application/WebPrintWriter.java index 46753ab080..634bf21d24 100644 --- a/impl/src/main/java/com/sun/faces/application/WebPrintWriter.java +++ b/impl/src/main/java/com/sun/faces/application/WebPrintWriter.java @@ -55,7 +55,7 @@ public NoOpWriter() { } @Override - public void write(char cbuf[], int off, int len) throws IOException { + public void write(char[] cbuf, int off, int len) throws IOException { // no-op } @@ -75,7 +75,7 @@ public void write(int c) throws IOException { } @Override - public void write(char cbuf[]) throws IOException { + public void write(char[] cbuf) throws IOException { // no-op } diff --git a/impl/src/main/java/com/sun/faces/application/WebappLifecycleListener.java b/impl/src/main/java/com/sun/faces/application/WebappLifecycleListener.java index f85da517f9..5f8e478880 100644 --- a/impl/src/main/java/com/sun/faces/application/WebappLifecycleListener.java +++ b/impl/src/main/java/com/sun/faces/application/WebappLifecycleListener.java @@ -56,7 +56,7 @@ public class WebappLifecycleListener { private ServletContext servletContext; private ApplicationAssociate applicationAssociate; - private Set activeSessions = ConcurrentHashMap.newKeySet(); + private final Set activeSessions = ConcurrentHashMap.newKeySet(); // ------------------------------------------------------------ Constructors diff --git a/impl/src/main/java/com/sun/faces/application/annotation/AnnotationManager.java b/impl/src/main/java/com/sun/faces/application/annotation/AnnotationManager.java index c53bb58f1f..cbd0a78ed6 100644 --- a/impl/src/main/java/com/sun/faces/application/annotation/AnnotationManager.java +++ b/impl/src/main/java/com/sun/faces/application/annotation/AnnotationManager.java @@ -102,7 +102,7 @@ private enum ProcessingTarget { Renderer(RENDERER_SCANNERS), SystemEvent(EVENTS_SCANNERS); - private Scanner[] scanners; + private final Scanner[] scanners; ProcessingTarget(Scanner[] scanners) { this.scanners = scanners; @@ -113,7 +113,7 @@ private enum ProcessingTarget { /** * The backing cache for all annotation metadata. */ - private ConcurrentMap, Future, RuntimeAnnotationHandler>>> cache; + private final ConcurrentMap, Future, RuntimeAnnotationHandler>>> cache; // ------------------------------------------------------------ Constructors @@ -317,8 +317,8 @@ private static final class ProcessAnnotationsTask implements Callable, RuntimeAnnotationHandler> EMPTY = Collections.EMPTY_MAP; - private Class clazz; - private Scanner[] scanners; + private final Class clazz; + private final Scanner[] scanners; // -------------------------------------------------------- Constructors diff --git a/impl/src/main/java/com/sun/faces/application/annotation/EJBHandler.java b/impl/src/main/java/com/sun/faces/application/annotation/EJBHandler.java index 56092138d0..37c534fe96 100644 --- a/impl/src/main/java/com/sun/faces/application/annotation/EJBHandler.java +++ b/impl/src/main/java/com/sun/faces/application/annotation/EJBHandler.java @@ -28,10 +28,10 @@ class EJBHandler extends JndiHandler implements RuntimeAnnotationHandler { private static final String JAVA_MODULE = "java:module/"; - private Field[] fields; - private EJB[] fieldAnnotations; - private Method[] methods; - private EJB[] methodAnnotations; + private final Field[] fields; + private final EJB[] fieldAnnotations; + private final Method[] methods; + private final EJB[] methodAnnotations; public EJBHandler(Field[] fields, EJB[] fieldAnnotations, Method[] methods, EJB[] methodAnnotations) { this.fields = fields; diff --git a/impl/src/main/java/com/sun/faces/application/annotation/FacesComponentUsage.java b/impl/src/main/java/com/sun/faces/application/annotation/FacesComponentUsage.java index 8cd651863b..22caec5b3e 100644 --- a/impl/src/main/java/com/sun/faces/application/annotation/FacesComponentUsage.java +++ b/impl/src/main/java/com/sun/faces/application/annotation/FacesComponentUsage.java @@ -19,8 +19,8 @@ import jakarta.faces.component.FacesComponent; public class FacesComponentUsage { - private Class target; - private FacesComponent annotation; + private final Class target; + private final FacesComponent annotation; public FacesComponentUsage(Class target, FacesComponent annotation) { this.target = target; diff --git a/impl/src/main/java/com/sun/faces/application/annotation/ListenerForHandler.java b/impl/src/main/java/com/sun/faces/application/annotation/ListenerForHandler.java index 84d70cd670..927febf17d 100644 --- a/impl/src/main/java/com/sun/faces/application/annotation/ListenerForHandler.java +++ b/impl/src/main/java/com/sun/faces/application/annotation/ListenerForHandler.java @@ -28,7 +28,7 @@ */ class ListenerForHandler implements RuntimeAnnotationHandler { - private ListenerFor[] listenersFor; + private final ListenerFor[] listenersFor; // ------------------------------------------------------------ Constructors @@ -57,18 +57,18 @@ public void apply(FacesContext ctx, Object... params) { } if (listener instanceof ComponentSystemEventListener) { - for (int i = 0, len = listenersFor.length; i < len; i++) { - target.subscribeToEvent(listenersFor[i].systemEventClass(), (ComponentSystemEventListener) listener); + for (ListenerFor listenerFor : listenersFor) { + target.subscribeToEvent(listenerFor.systemEventClass(), (ComponentSystemEventListener) listener); } } else if (listener instanceof SystemEventListener) { Class sourceClassValue = null; Application app = ctx.getApplication(); - for (int i = 0, len = listenersFor.length; i < len; i++) { - sourceClassValue = listenersFor[i].sourceClass(); + for (ListenerFor listenerFor : listenersFor) { + sourceClassValue = listenerFor.sourceClass(); if (sourceClassValue == Void.class) { - app.subscribeToEvent(listenersFor[i].systemEventClass(), (SystemEventListener) listener); + app.subscribeToEvent(listenerFor.systemEventClass(), (SystemEventListener) listener); } else { - app.subscribeToEvent(listenersFor[i].systemEventClass(), listenersFor[i].sourceClass(), (SystemEventListener) listener); + app.subscribeToEvent(listenerFor.systemEventClass(), listenerFor.sourceClass(), (SystemEventListener) listener); } } diff --git a/impl/src/main/java/com/sun/faces/application/annotation/PersistenceContextHandler.java b/impl/src/main/java/com/sun/faces/application/annotation/PersistenceContextHandler.java index 069efaab2a..bfd9af4710 100644 --- a/impl/src/main/java/com/sun/faces/application/annotation/PersistenceContextHandler.java +++ b/impl/src/main/java/com/sun/faces/application/annotation/PersistenceContextHandler.java @@ -27,10 +27,10 @@ */ class PersistenceContextHandler extends JndiHandler implements RuntimeAnnotationHandler { - private Method[] methods; - private PersistenceContext[] methodAnnotations; - private Field[] fields; - private PersistenceContext[] fieldAnnotations; + private final Method[] methods; + private final PersistenceContext[] methodAnnotations; + private final Field[] fields; + private final PersistenceContext[] fieldAnnotations; public PersistenceContextHandler(Method[] methods, PersistenceContext[] methodAnnotations, Field[] fields, PersistenceContext[] fieldAnnotations) { this.methods = methods; diff --git a/impl/src/main/java/com/sun/faces/application/annotation/PersistenceUnitHandler.java b/impl/src/main/java/com/sun/faces/application/annotation/PersistenceUnitHandler.java index 573ae3d954..644d82f4d6 100644 --- a/impl/src/main/java/com/sun/faces/application/annotation/PersistenceUnitHandler.java +++ b/impl/src/main/java/com/sun/faces/application/annotation/PersistenceUnitHandler.java @@ -27,10 +27,10 @@ */ class PersistenceUnitHandler extends JndiHandler implements RuntimeAnnotationHandler { - private Method[] methods; - private PersistenceUnit[] methodAnnotations; - private Field[] fields; - private PersistenceUnit[] fieldAnnotations; + private final Method[] methods; + private final PersistenceUnit[] methodAnnotations; + private final Field[] fields; + private final PersistenceUnit[] fieldAnnotations; public PersistenceUnitHandler(Method[] methods, PersistenceUnit[] methodAnnotations, Field[] fields, PersistenceUnit[] fieldAnnotations) { this.methods = methods; diff --git a/impl/src/main/java/com/sun/faces/application/annotation/ResourceDependencyHandler.java b/impl/src/main/java/com/sun/faces/application/annotation/ResourceDependencyHandler.java index 3a62d9941f..e1c3d56628 100644 --- a/impl/src/main/java/com/sun/faces/application/annotation/ResourceDependencyHandler.java +++ b/impl/src/main/java/com/sun/faces/application/annotation/ResourceDependencyHandler.java @@ -35,8 +35,8 @@ */ class ResourceDependencyHandler implements RuntimeAnnotationHandler { - private ResourceDependency[] dependencies; - private Map expressionsMap; + private final ResourceDependency[] dependencies; + private final Map expressionsMap; // ------------------------------------------------------------ Constructors diff --git a/impl/src/main/java/com/sun/faces/application/annotation/ResourceHandler.java b/impl/src/main/java/com/sun/faces/application/annotation/ResourceHandler.java index f0863ec6c2..9335013380 100644 --- a/impl/src/main/java/com/sun/faces/application/annotation/ResourceHandler.java +++ b/impl/src/main/java/com/sun/faces/application/annotation/ResourceHandler.java @@ -27,10 +27,10 @@ */ class ResourceHandler extends JndiHandler { - private Field[] fields; - private Resource[] fieldAnnotations; - private Method[] methods; - private Resource[] methodAnnotations; + private final Field[] fields; + private final Resource[] fieldAnnotations; + private final Method[] methods; + private final Resource[] methodAnnotations; public ResourceHandler(Field[] fields, Resource[] fieldAnnotations, Method[] methods, Resource[] methodAnnotations) { this.fields = fields; diff --git a/impl/src/main/java/com/sun/faces/application/annotation/WebServiceRefHandler.java b/impl/src/main/java/com/sun/faces/application/annotation/WebServiceRefHandler.java index ea8b6cef04..ba0aaa9334 100644 --- a/impl/src/main/java/com/sun/faces/application/annotation/WebServiceRefHandler.java +++ b/impl/src/main/java/com/sun/faces/application/annotation/WebServiceRefHandler.java @@ -27,10 +27,10 @@ */ class WebServiceRefHandler extends JndiHandler implements RuntimeAnnotationHandler { - private Field[] fields; - private WebServiceRef[] fieldAnnotations; - private Method[] methods; - private WebServiceRef[] methodAnnotations; + private final Field[] fields; + private final WebServiceRef[] fieldAnnotations; + private final Method[] methods; + private final WebServiceRef[] methodAnnotations; public WebServiceRefHandler(Field[] fields, WebServiceRef[] fieldAnnotations, Method[] methods, WebServiceRef[] methodAnnotations) { this.fields = fields; diff --git a/impl/src/main/java/com/sun/faces/application/applicationimpl/Events.java b/impl/src/main/java/com/sun/faces/application/applicationimpl/Events.java index 5dbe1c4346..a7cd0c5642 100644 --- a/impl/src/main/java/com/sun/faces/application/applicationimpl/Events.java +++ b/impl/src/main/java/com/sun/faces/application/applicationimpl/Events.java @@ -63,7 +63,7 @@ public class Events { * on a per-FacesContext, per-SystemEvent.class type basis. */ - private ReentrantLisneterInvocationGuard listenerInvocationGuard = new ReentrantLisneterInvocationGuard(); + private final ReentrantLisneterInvocationGuard listenerInvocationGuard = new ReentrantLisneterInvocationGuard(); /* * @see jakarta.faces.application.Application#publishEvent(FacesContext, Class, Class, Object) @@ -259,7 +259,7 @@ private SystemEvent processListenersAccountingForAdds(List // if original differs from copy, make a new copy. // The new copy consists of the original list - processed - SystemEventListener listenersCopy[] = new SystemEventListener[listeners.size()]; + SystemEventListener[] listenersCopy = new SystemEventListener[listeners.size()]; int i = 0; for (i = 0; i < listenersCopy.length; i++) { listenersCopy[i] = listeners.get(i); @@ -298,7 +298,7 @@ private SystemEvent processListenersAccountingForAdds(List } - private boolean originalDiffersFromCopy(Collection original, SystemEventListener copy[]) { + private boolean originalDiffersFromCopy(Collection original, SystemEventListener[] copy) { boolean foundDifference = false; int i = 0, originalLen = original.size(), copyLen = copy.length; diff --git a/impl/src/main/java/com/sun/faces/application/applicationimpl/ExpressionLanguage.java b/impl/src/main/java/com/sun/faces/application/applicationimpl/ExpressionLanguage.java index f24a728b15..772e282e46 100644 --- a/impl/src/main/java/com/sun/faces/application/applicationimpl/ExpressionLanguage.java +++ b/impl/src/main/java/com/sun/faces/application/applicationimpl/ExpressionLanguage.java @@ -40,8 +40,8 @@ public class ExpressionLanguage { private final ApplicationAssociate associate; - private List elContextListeners; - private CompositeELResolver elResolvers; + private final List elContextListeners; + private final CompositeELResolver elResolvers; private volatile FacesCompositeELResolver compositeELResolver; public ExpressionLanguage(ApplicationAssociate applicationAssociate) { diff --git a/impl/src/main/java/com/sun/faces/application/applicationimpl/InstanceFactory.java b/impl/src/main/java/com/sun/faces/application/applicationimpl/InstanceFactory.java index 7617eec378..71db771f5a 100644 --- a/impl/src/main/java/com/sun/faces/application/applicationimpl/InstanceFactory.java +++ b/impl/src/main/java/com/sun/faces/application/applicationimpl/InstanceFactory.java @@ -117,9 +117,9 @@ public class InstanceFactory { private final String[] STANDARD_BY_TYPE_CONVERTER_CLASSES = { "java.math.BigDecimal", "java.lang.Boolean", "java.lang.Byte", "java.lang.Character", "java.lang.Double", "java.lang.Float", "java.lang.Integer", "java.lang.Long", "java.lang.Short", "java.lang.Enum" }; - private Map, Object> converterTypeMap; - private boolean registerPropertyEditors; - private boolean passDefaultTimeZone; + private final Map, Object> converterTypeMap; + private final boolean registerPropertyEditors; + private final boolean passDefaultTimeZone; private TimeZone systemTimeZone; @@ -130,12 +130,12 @@ private static final class ComponentResourceClassNotFound { // These four maps store store "identifier" | "class name" // mappings. // - private ViewMemberInstanceFactoryMetadataMap componentMap; - private ViewMemberInstanceFactoryMetadataMap behaviorMap; - private ViewMemberInstanceFactoryMetadataMap converterIdMap; - private ViewMemberInstanceFactoryMetadataMap validatorMap; + private final ViewMemberInstanceFactoryMetadataMap componentMap; + private final ViewMemberInstanceFactoryMetadataMap behaviorMap; + private final ViewMemberInstanceFactoryMetadataMap converterIdMap; + private final ViewMemberInstanceFactoryMetadataMap validatorMap; - private Set defaultValidatorIds; + private final Set defaultValidatorIds; private volatile Map defaultValidatorInfo; private final ApplicationAssociate associate; diff --git a/impl/src/main/java/com/sun/faces/application/applicationimpl/SearchExpression.java b/impl/src/main/java/com/sun/faces/application/applicationimpl/SearchExpression.java index b0dd0829cc..417c497139 100644 --- a/impl/src/main/java/com/sun/faces/application/applicationimpl/SearchExpression.java +++ b/impl/src/main/java/com/sun/faces/application/applicationimpl/SearchExpression.java @@ -49,7 +49,7 @@ public class SearchExpression { private final ApplicationAssociate associate; - private CompositeSearchKeywordResolver searchKeywordResolvers; + private final CompositeSearchKeywordResolver searchKeywordResolvers; public SearchExpression(ApplicationAssociate applicationAssociate) { associate = applicationAssociate; diff --git a/impl/src/main/java/com/sun/faces/application/applicationimpl/events/ComponentSystemEventHelper.java b/impl/src/main/java/com/sun/faces/application/applicationimpl/events/ComponentSystemEventHelper.java index 46fe5f1ad9..60c79da794 100644 --- a/impl/src/main/java/com/sun/faces/application/applicationimpl/events/ComponentSystemEventHelper.java +++ b/impl/src/main/java/com/sun/faces/application/applicationimpl/events/ComponentSystemEventHelper.java @@ -26,7 +26,7 @@ */ public class ComponentSystemEventHelper { - private Cache, Cache, EventInfo>> sourceCache; + private final Cache, Cache, EventInfo>> sourceCache; // -------------------------------------------------------- Constructors diff --git a/impl/src/main/java/com/sun/faces/application/applicationimpl/events/EventInfo.java b/impl/src/main/java/com/sun/faces/application/applicationimpl/events/EventInfo.java index 856ee0445a..4ca48d548f 100644 --- a/impl/src/main/java/com/sun/faces/application/applicationimpl/events/EventInfo.java +++ b/impl/src/main/java/com/sun/faces/application/applicationimpl/events/EventInfo.java @@ -39,11 +39,11 @@ public class EventInfo { private static final Logger LOGGER = FacesLogger.APPLICATION.getLogger(); - private Class systemEvent; - private Class sourceClass; - private Set listeners; + private final Class systemEvent; + private final Class sourceClass; + private final Set listeners; private Constructor eventConstructor; - private Map, Constructor> constructorMap; + private final Map, Constructor> constructorMap; // -------------------------------------------------------- Constructors diff --git a/impl/src/main/java/com/sun/faces/application/applicationimpl/events/SystemEventInfo.java b/impl/src/main/java/com/sun/faces/application/applicationimpl/events/SystemEventInfo.java index 23a1a832a8..75833aca33 100644 --- a/impl/src/main/java/com/sun/faces/application/applicationimpl/events/SystemEventInfo.java +++ b/impl/src/main/java/com/sun/faces/application/applicationimpl/events/SystemEventInfo.java @@ -29,7 +29,7 @@ public class SystemEventInfo { private Class systemEvent; - private Cache, EventInfo> cache = new Cache<>(arg -> new EventInfo(systemEvent, arg)); + private final Cache, EventInfo> cache = new Cache<>(arg -> new EventInfo(systemEvent, arg)); // -------------------------------------------------------- Constructors diff --git a/impl/src/main/java/com/sun/faces/application/resource/ClasspathResourceHelper.java b/impl/src/main/java/com/sun/faces/application/resource/ClasspathResourceHelper.java index 543838c487..4cc09417b2 100644 --- a/impl/src/main/java/com/sun/faces/application/resource/ClasspathResourceHelper.java +++ b/impl/src/main/java/com/sun/faces/application/resource/ClasspathResourceHelper.java @@ -47,9 +47,9 @@ public class ClasspathResourceHelper extends ResourceHelper { private static final String BASE_RESOURCE_PATH = "META-INF/resources"; - private boolean cacheTimestamp; + private final boolean cacheTimestamp; private volatile ZipDirectoryEntryScanner libraryScanner; - private boolean enableMissingResourceLibraryDetection; + private final boolean enableMissingResourceLibraryDetection; // ------------------------------------------------------------ Constructors diff --git a/impl/src/main/java/com/sun/faces/application/resource/FaceletLibraryInfo.java b/impl/src/main/java/com/sun/faces/application/resource/FaceletLibraryInfo.java index d3b2e07cad..6dfcca7a08 100644 --- a/impl/src/main/java/com/sun/faces/application/resource/FaceletLibraryInfo.java +++ b/impl/src/main/java/com/sun/faces/application/resource/FaceletLibraryInfo.java @@ -20,7 +20,7 @@ public class FaceletLibraryInfo extends LibraryInfo { - private URL url; + private final URL url; public FaceletLibraryInfo(String name, VersionInfo version, String localePrefix, String contract, ResourceHelper helper, URL url) { super(name, version, localePrefix, contract, helper); diff --git a/impl/src/main/java/com/sun/faces/application/resource/FaceletResourceInfo.java b/impl/src/main/java/com/sun/faces/application/resource/FaceletResourceInfo.java index 5da7671b5b..63cea6acb9 100644 --- a/impl/src/main/java/com/sun/faces/application/resource/FaceletResourceInfo.java +++ b/impl/src/main/java/com/sun/faces/application/resource/FaceletResourceInfo.java @@ -25,7 +25,7 @@ public class FaceletResourceInfo extends ResourceInfo { this.url = url; } - private URL url; + private final URL url; public URL getUrl() { return url; diff --git a/impl/src/main/java/com/sun/faces/application/resource/LibraryInfo.java b/impl/src/main/java/com/sun/faces/application/resource/LibraryInfo.java index 5f4a54e291..7f42eafded 100644 --- a/impl/src/main/java/com/sun/faces/application/resource/LibraryInfo.java +++ b/impl/src/main/java/com/sun/faces/application/resource/LibraryInfo.java @@ -24,11 +24,11 @@ */ public class LibraryInfo { - private String name; - private VersionInfo version; + private final String name; + private final VersionInfo version; private String localePrefix; private String contract; - private ResourceHelper helper; + private final ResourceHelper helper; private String path; private String nonLocalizedPath; diff --git a/impl/src/main/java/com/sun/faces/application/resource/ResourceCache.java b/impl/src/main/java/com/sun/faces/application/resource/ResourceCache.java index c722cbb5e0..6e2cffe3d1 100644 --- a/impl/src/main/java/com/sun/faces/application/resource/ResourceCache.java +++ b/impl/src/main/java/com/sun/faces/application/resource/ResourceCache.java @@ -153,7 +153,7 @@ private static String getServletContextIdentifier(ServletContext context) { private static final class ResourceInfoCheckPeriodProxy { - private ResourceInfo resourceInfo; + private final ResourceInfo resourceInfo; private Long checkTime; // -------------------------------------------------------- Constructors diff --git a/impl/src/main/java/com/sun/faces/application/resource/ResourceHandlerImpl.java b/impl/src/main/java/com/sun/faces/application/resource/ResourceHandlerImpl.java index b0b822afa4..d62a8907a3 100644 --- a/impl/src/main/java/com/sun/faces/application/resource/ResourceHandlerImpl.java +++ b/impl/src/main/java/com/sun/faces/application/resource/ResourceHandlerImpl.java @@ -70,7 +70,7 @@ public class ResourceHandlerImpl extends ResourceHandler { List excludePatterns; private long creationTime; private long maxAge; - private WebConfiguration webconfig; + private final WebConfiguration webconfig; // ------------------------------------------------------------ Constructors @@ -203,7 +203,7 @@ public boolean libraryExists(String libraryName) { @Override public boolean isResourceRequest(FacesContext context) { - Boolean isResourceRequest = (Boolean) RequestStateManager.get(context, RESOURCE_REQUEST); + Boolean isResourceRequest = RequestStateManager.get(context, RESOURCE_REQUEST); if (isResourceRequest == null) { String resourceId = normalizeResourceRequest(context); isResourceRequest = resourceId != null ? resourceId.startsWith(RESOURCE_IDENTIFIER) : FALSE; @@ -220,9 +220,9 @@ public String getRendererTypeForResourceName(String resourceName) { String contentType = getContentType(FacesContext.getCurrentInstance(), resourceName); if (null != contentType) { contentType = contentType.toLowerCase(); - if (-1 != contentType.indexOf("javascript")) { + if (contentType.contains("javascript")) { rendererType = "jakarta.faces.resource.Script"; - } else if (-1 != contentType.indexOf("css")) { + } else if (contentType.contains("css")) { rendererType = "jakarta.faces.resource.Stylesheet"; } } diff --git a/impl/src/main/java/com/sun/faces/application/resource/ResourceHelper.java b/impl/src/main/java/com/sun/faces/application/resource/ResourceHelper.java index 7c84420def..337c3d394c 100644 --- a/impl/src/main/java/com/sun/faces/application/resource/ResourceHelper.java +++ b/impl/src/main/java/com/sun/faces/application/resource/ResourceHelper.java @@ -533,12 +533,12 @@ private VersionInfo getVersion(String pathElement, boolean isResource) { private static final class ELEvaluatingInputStream extends InputStream { // Premature optimization is the root of all evil. Blah blah. - private List buf = new ArrayList<>(1024); + private final List buf = new ArrayList<>(1024); private boolean failedExpressionTest = false; private boolean writingExpression = false; - private InputStream inner; - private ClientResourceInfo info; - private FacesContext ctx; + private final InputStream inner; + private final ClientResourceInfo info; + private final FacesContext ctx; private boolean expressionEvaluated; private boolean endOfStreamReached; @@ -632,7 +632,7 @@ private void readExpressionIntoBufferAndEvaluateIntoBuffer() throws IOException * a String, turn the String into a ValueExpression, evaluate it, store the toString() of it in expressionResult; */ private void evaluateExpressionIntoBuffer() { - char chars[] = new char[buf.size()]; + char[] chars = new char[buf.size()]; for (int i = 0, len = buf.size(); i < len; i++) { chars[i] = (char) (int) buf.get(i); } diff --git a/impl/src/main/java/com/sun/faces/application/resource/ResourceManager.java b/impl/src/main/java/com/sun/faces/application/resource/ResourceManager.java index 2a491fa2b8..f6ac1887dd 100644 --- a/impl/src/main/java/com/sun/faces/application/resource/ResourceManager.java +++ b/impl/src/main/java/com/sun/faces/application/resource/ResourceManager.java @@ -57,22 +57,22 @@ public class ResourceManager { */ private static final Pattern CONFIG_MIMETYPE_PATTERN = Pattern.compile("[a-z-]*/[a-z0-9.\\*-]*"); - private FaceletWebappResourceHelper faceletWebappResourceHelper = new FaceletWebappResourceHelper(); + private final FaceletWebappResourceHelper faceletWebappResourceHelper = new FaceletWebappResourceHelper(); /** * {@link ResourceHelper} used for looking up webapp-based resources. */ - private ResourceHelper webappResourceHelper = new WebappResourceHelper(); + private final ResourceHelper webappResourceHelper = new WebappResourceHelper(); /** * {@link ResourceHelper} used for looking up classpath-based resources. */ - private ClasspathResourceHelper classpathResourceHelper = new ClasspathResourceHelper(); + private final ClasspathResourceHelper classpathResourceHelper = new ClasspathResourceHelper(); /** * Cache for storing {@link ResourceInfo} instances to reduce the cost of the resource lookups. */ - private ResourceCache cache; + private final ResourceCache cache; /** * Patterns used to find {@link ResourceInfo} instances that may have their content compressed. @@ -83,7 +83,7 @@ public class ResourceManager { * This lock is used to ensure the lookup of compressable {@link ResourceInfo} instances are atomic to prevent theading * issues when writing the compressed content during a lookup. */ - private ReentrantLock lock = new ReentrantLock(); + private final ReentrantLock lock = new ReentrantLock(); // ------------------------------------------------------------ Constructors diff --git a/impl/src/main/java/com/sun/faces/application/resource/VersionInfo.java b/impl/src/main/java/com/sun/faces/application/resource/VersionInfo.java index 818f2e8e7f..9985a0a940 100644 --- a/impl/src/main/java/com/sun/faces/application/resource/VersionInfo.java +++ b/impl/src/main/java/com/sun/faces/application/resource/VersionInfo.java @@ -19,10 +19,10 @@ /** * Metadata pertaining to versions. */ -public class VersionInfo implements Comparable { +public class VersionInfo implements Comparable { - private String version; - private String extension; + private final String version; + private final String extension; // ------------------------------------------------------------ Constructors @@ -75,7 +75,7 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (obj == null || !(obj instanceof VersionInfo)) { + if (!(obj instanceof VersionInfo)) { return false; } if (this == obj) { @@ -96,9 +96,8 @@ public boolean equals(Object obj) { // ------------------------------------------------- Methods from Comparable @Override - public int compareTo(Object o) { - assert o instanceof VersionInfo; - VersionInfo c = (VersionInfo) o; - return version.compareTo(c.version); + public int compareTo(VersionInfo versionInfo) { + assert versionInfo != null; + return version.compareTo(versionInfo.version); } } diff --git a/impl/src/main/java/com/sun/faces/application/resource/WebappResourceHelper.java b/impl/src/main/java/com/sun/faces/application/resource/WebappResourceHelper.java index 6a4374e6ee..702b42ddbb 100644 --- a/impl/src/main/java/com/sun/faces/application/resource/WebappResourceHelper.java +++ b/impl/src/main/java/com/sun/faces/application/resource/WebappResourceHelper.java @@ -54,7 +54,7 @@ public class WebappResourceHelper extends ResourceHelper { private final String BASE_CONTRACTS_PATH; - private boolean cacheTimestamp; + private final boolean cacheTimestamp; // ------------------------------------------------------------ Constructors @@ -162,7 +162,7 @@ public LibraryInfo findLibrary(String libraryName, String localePrefix, String c Set resourcePaths = ctx.getExternalContext().getResourcePaths(path); // it could be possible that there exists an empty directory // that is representing the library, but if it's empty, treat it - // as non-existant and return null. + // as non-existent and return null. if (resourcePaths != null && !resourcePaths.isEmpty()) { VersionInfo version = getVersion(resourcePaths, false); return new LibraryInfo(libraryName, version, localePrefix, contract, this); diff --git a/impl/src/main/java/com/sun/faces/application/view/FaceletViewHandlingStrategy.java b/impl/src/main/java/com/sun/faces/application/view/FaceletViewHandlingStrategy.java index 2324424349..2bcaa418c4 100644 --- a/impl/src/main/java/com/sun/faces/application/view/FaceletViewHandlingStrategy.java +++ b/impl/src/main/java/com/sun/faces/application/view/FaceletViewHandlingStrategy.java @@ -165,7 +165,7 @@ public class FaceletViewHandlingStrategy extends ViewHandlingStrategy { public static final String RESOURCE_LIBRARY_CONTRACT_DATA_STRUCTURE_KEY = FaceletViewHandlingStrategy.class.getName() + ".RESOURCE_LIBRARY_CONTRACT_DATA_STRUCTURE"; - private MethodRetargetHandlerManager retargetHandlerManager = new MethodRetargetHandlerManager(); + private final MethodRetargetHandlerManager retargetHandlerManager = new MethodRetargetHandlerManager(); private int responseBufferSize; diff --git a/impl/src/main/java/com/sun/faces/application/view/FormOmittedChecker.java b/impl/src/main/java/com/sun/faces/application/view/FormOmittedChecker.java index 1375e70e9d..614ce02a51 100644 --- a/impl/src/main/java/com/sun/faces/application/view/FormOmittedChecker.java +++ b/impl/src/main/java/com/sun/faces/application/view/FormOmittedChecker.java @@ -42,7 +42,7 @@ class FormOmittedChecker { /** * Stores the skip hint. */ - private static String SKIP_ITERATION_HINT = "jakarta.faces.visit.SKIP_ITERATION"; + private static final String SKIP_ITERATION_HINT = "jakarta.faces.visit.SKIP_ITERATION"; /** * Constructor. diff --git a/impl/src/main/java/com/sun/faces/application/view/MultiViewHandler.java b/impl/src/main/java/com/sun/faces/application/view/MultiViewHandler.java index bb131daa0f..68d6c7a05a 100644 --- a/impl/src/main/java/com/sun/faces/application/view/MultiViewHandler.java +++ b/impl/src/main/java/com/sun/faces/application/view/MultiViewHandler.java @@ -85,10 +85,10 @@ public class MultiViewHandler extends ViewHandler { // Log instance for this class private static final Logger LOGGER = FacesLogger.APPLICATION.getLogger(); - private List configuredExtensions; - private Set protectedViews; + private final List configuredExtensions; + private final Set protectedViews; - private ViewDeclarationLanguageFactory vdlFactory; + private final ViewDeclarationLanguageFactory vdlFactory; // ------------------------------------------------------------ Constructors @@ -582,11 +582,7 @@ protected void addViewParameters(FacesContext ctx, String viewId, Map existing = existingParameters.get(viewParam.getName()); - if (existing == null) { - existing = new ArrayList<>(4); - existingParameters.put(viewParam.getName(), existing); - } + List existing = existingParameters.computeIfAbsent(viewParam.getName(), k -> new ArrayList<>(4)); existing.add(value); } } diff --git a/impl/src/main/java/com/sun/faces/application/view/ViewMetadataImpl.java b/impl/src/main/java/com/sun/faces/application/view/ViewMetadataImpl.java index 999d513360..1f9f06d034 100644 --- a/impl/src/main/java/com/sun/faces/application/view/ViewMetadataImpl.java +++ b/impl/src/main/java/com/sun/faces/application/view/ViewMetadataImpl.java @@ -47,7 +47,7 @@ */ public class ViewMetadataImpl extends ViewMetadata { - private String viewId; + private final String viewId; private DefaultFaceletFactory faceletFactory; // ---------------------------------------------------------------------------------------------------- Constructors diff --git a/impl/src/main/java/com/sun/faces/application/view/ViewScopeManager.java b/impl/src/main/java/com/sun/faces/application/view/ViewScopeManager.java index e43d03d757..cbeb3446b0 100644 --- a/impl/src/main/java/com/sun/faces/application/view/ViewScopeManager.java +++ b/impl/src/main/java/com/sun/faces/application/view/ViewScopeManager.java @@ -76,9 +76,9 @@ public class ViewScopeManager implements HttpSessionListener, ViewMapListener { /** * Stores the CDI context manager. */ - private ViewScopeContextManager contextManager; + private final ViewScopeContextManager contextManager; - private boolean distributable; + private final boolean distributable; private Integer numberOfActiveViewMapsInWebXml; diff --git a/impl/src/main/java/com/sun/faces/application/view/WriteBehindStateWriter.java b/impl/src/main/java/com/sun/faces/application/view/WriteBehindStateWriter.java index 8423dd268c..25bc11c203 100644 --- a/impl/src/main/java/com/sun/faces/application/view/WriteBehindStateWriter.java +++ b/impl/src/main/java/com/sun/faces/application/view/WriteBehindStateWriter.java @@ -43,12 +43,12 @@ final class WriteBehindStateWriter extends Writer { private static final ThreadLocal CUR_WRITER = new ThreadLocal<>(); private Writer out; - private Writer orig; + private final Writer orig; private FastStringWriter fWriter; private boolean stateWritten; - private int bufSize; - private char[] buf; - private FacesContext context; + private final int bufSize; + private final char[] buf; + private final FacesContext context; private Object state; // -------------------------------------------------------- Constructors @@ -87,7 +87,7 @@ public void write(int c) throws IOException { * @see Writer#write(char[]) */ @Override - public void write(char cbuf[]) throws IOException { + public void write(char[] cbuf) throws IOException { out.write(cbuf); } @@ -117,7 +117,7 @@ public void write(String str, int off, int len) throws IOException { * @see Writer#write(char[], int, int) */ @Override - public void write(char cbuf[], int off, int len) throws IOException { + public void write(char[] cbuf, int off, int len) throws IOException { out.write(cbuf, off, len); } @@ -207,7 +207,7 @@ public void flushToWriter() throws IOException { int len = tildeIdx - pos; orig.write(buf, 0, len); // Now check to see if the state saving string is - // at the begining of pos, if so, write our + // at the beginning of pos, if so, write our // state out. if (builder.indexOf(RIConstants.SAVESTATE_FIELD_MARKER, pos) == tildeIdx) { // buf is effectively zero'd out at this point diff --git a/impl/src/main/java/com/sun/faces/cdi/CdiExtension.java b/impl/src/main/java/com/sun/faces/cdi/CdiExtension.java index aeae4a8869..a5129a90c2 100644 --- a/impl/src/main/java/com/sun/faces/cdi/CdiExtension.java +++ b/impl/src/main/java/com/sun/faces/cdi/CdiExtension.java @@ -76,7 +76,7 @@ public class CdiExtension implements Extension { /** * Map of {@code @ManagedProperty} target types */ - private Set managedPropertyTargetTypes = new HashSet<>(); + private final Set managedPropertyTargetTypes = new HashSet<>(); /** * Stores the logger. diff --git a/impl/src/main/java/com/sun/faces/cdi/CdiProducer.java b/impl/src/main/java/com/sun/faces/cdi/CdiProducer.java index 41eb33c21e..654dd417ee 100644 --- a/impl/src/main/java/com/sun/faces/cdi/CdiProducer.java +++ b/impl/src/main/java/com/sun/faces/cdi/CdiProducer.java @@ -50,7 +50,7 @@ abstract class CdiProducer implements Bean, PassivationCapable, Serializab private String id = this.getClass().getName(); private String name; // for synthetic beans, the beanClass defaults to the extension that registers them - private Class beanClass = CdiExtension.class; + private final Class beanClass = CdiExtension.class; private Set types = singleton(Object.class); private Set qualifiers = unmodifiableSet(asSet(new DefaultAnnotationLiteral(), new AnyAnnotationLiteral())); private Class scope = Dependent.class; diff --git a/impl/src/main/java/com/sun/faces/component/CompositeComponentStackManager.java b/impl/src/main/java/com/sun/faces/component/CompositeComponentStackManager.java index 203382e111..08cd96a9c6 100644 --- a/impl/src/main/java/com/sun/faces/component/CompositeComponentStackManager.java +++ b/impl/src/main/java/com/sun/faces/component/CompositeComponentStackManager.java @@ -52,8 +52,8 @@ public enum StackType { TreeCreation, Evaluation } - private StackHandler treeCreation = new TreeCreationStackHandler(); - private StackHandler runtime = new RuntimeStackHandler(); + private final StackHandler treeCreation = new TreeCreationStackHandler(); + private final StackHandler runtime = new RuntimeStackHandler(); // ------------------------------------------------------------ Constructors @@ -281,7 +281,7 @@ private final class RuntimeStackHandler extends BaseStackHandler { @Override public void delete() { - Stack s = getStack(false); + Stack s = getStack(false); if (s != null) { s.clear(); } @@ -291,7 +291,7 @@ public void delete() { @Override public void pop() { - Stack s = getStack(false); + Stack s = getStack(false); if (s != null && !s.isEmpty()) { s.pop(); } @@ -371,7 +371,7 @@ private final class TreeCreationStackHandler extends BaseStackHandler { @Override public void pop() { - Stack s = getStack(false); + Stack s = getStack(false); if (s != null && !stack.isEmpty()) { stack.pop(); if (stack.isEmpty()) { diff --git a/impl/src/main/java/com/sun/faces/component/validator/ComponentValidators.java b/impl/src/main/java/com/sun/faces/component/validator/ComponentValidators.java index dc897b7186..25b7c19aea 100644 --- a/impl/src/main/java/com/sun/faces/component/validator/ComponentValidators.java +++ b/impl/src/main/java/com/sun/faces/component/validator/ComponentValidators.java @@ -138,18 +138,14 @@ public void addValidators(FacesContext ctx, EditableValueHolder editableValueHol Set keySet = defaultValidatorInfo.keySet(); List validatorIds = new ArrayList<>(keySet.size()); - for (String key : keySet) { - validatorIds.add(key); - } + validatorIds.addAll(keySet); Set disabledIds = (Set) RequestStateManager.remove(ctx, RequestStateManager.DISABLED_VALIDATORS); int count = validatorStack.size(); for (int i = count - 1; i >= 0; i--) { ValidatorInfo info = validatorStack.get(i); if (!info.isEnabled() || disabledIds != null && disabledIds.contains(info.getValidatorId())) { - if (validatorIds.contains(info.getValidatorId())) { - validatorIds.remove(info.getValidatorId()); - } + validatorIds.remove(info.getValidatorId()); } else { if (!validatorIds.contains(info.getValidatorId())) { validatorIds.add(info.getValidatorId()); @@ -209,11 +205,11 @@ private static void addValidatorsToComponent(FacesContext ctx, Collection defaultValidatorInfo = application.getDefaultValidatorInfo(); - Validator[] validators = editableValueHolder.getValidators(); + Validator[] validators = editableValueHolder.getValidators(); // check to make sure that Validator instances haven't already // been added. for (Map.Entry defaultValidator : defaultValidatorInfo.entrySet()) { - for (Validator validator : validators) { + for (Validator validator : validators) { if (defaultValidator.getValue().equals(validator.getClass().getName())) { validatorIds.remove(defaultValidator.getKey()); break; @@ -224,7 +220,7 @@ private static void addValidatorsToComponent(FacesContext ctx, Collection v = application.createValidator(id); // work backwards up the stack of ValidatorInfo to find the // nearest matching ValidatorInfo to apply attributes if (validatorStack != null) { @@ -248,10 +244,10 @@ private static void addValidatorsToComponent(FacesContext ctx, Collection hints; + private final Set hints; } diff --git a/impl/src/main/java/com/sun/faces/config/ConfigManager.java b/impl/src/main/java/com/sun/faces/config/ConfigManager.java index 99591b0bb5..a5a06fb8cf 100644 --- a/impl/src/main/java/com/sun/faces/config/ConfigManager.java +++ b/impl/src/main/java/com/sun/faces/config/ConfigManager.java @@ -128,10 +128,9 @@ public class ConfigManager { * when the application is destroyed. *

*/ - private List initializedContexts = new CopyOnWriteArrayList<>(); + private final List initializedContexts = new CopyOnWriteArrayList<>(); - private final List configProcessors = unmodifiableList( - asList( + private final List configProcessors = List.of( new FactoryConfigProcessor(), new LifecycleConfigProcessor(), new ApplicationConfigProcessor(), @@ -144,7 +143,7 @@ public class ConfigManager { new FacesConfigExtensionProcessor(), new ProtectedViewsConfigProcessor(), new FacesFlowDefinitionConfigProcessor(), - new ResourceLibraryContractsConfigProcessor())); + new ResourceLibraryContractsConfigProcessor()); /** *

@@ -152,8 +151,8 @@ public class ConfigManager { * Mojarra, and two other providers to satisfy the requirements of the specification. *

*/ - private final List facesConfigProviders = unmodifiableList( - asList(new MetaInfFacesConfigResourceProvider(), new WebAppFlowConfigResourceProvider(), new WebFacesConfigResourceProvider())); + private final List facesConfigProviders = List.of( + new MetaInfFacesConfigResourceProvider(), new WebAppFlowConfigResourceProvider(), new WebFacesConfigResourceProvider()); /** *

@@ -161,8 +160,8 @@ public class ConfigManager { * Mojarra, and one other providers to satisfy the requirements of the specification. *

*/ - private final List facesletsTagLibConfigProviders = unmodifiableList( - asList(new MetaInfFaceletTaglibraryConfigProvider(), new WebFaceletTaglibResourceProvider())); + private final List facesletsTagLibConfigProviders = List.of( + new MetaInfFaceletTaglibraryConfigProvider(), new WebFaceletTaglibResourceProvider()); /** *

@@ -403,7 +402,7 @@ private List getConfigPopulators() { configPopulators.add(new MojarraRuntimePopulator()); - ServiceLoader.load(ApplicationConfigurationPopulator.class).forEach(e -> configPopulators.add(e)); + ServiceLoader.load(ApplicationConfigurationPopulator.class).forEach(configPopulators::add); return configPopulators; } diff --git a/impl/src/main/java/com/sun/faces/config/ConfigureListener.java b/impl/src/main/java/com/sun/faces/config/ConfigureListener.java index fa975e1f73..fbe1f9a190 100644 --- a/impl/src/main/java/com/sun/faces/config/ConfigureListener.java +++ b/impl/src/main/java/com/sun/faces/config/ConfigureListener.java @@ -687,7 +687,7 @@ public void endElement(String uri, String localName, String qName) throws SAXExc private class WebConfigResourceMonitor implements Runnable { private List monitors; - private ServletContext servletContext; + private final ServletContext servletContext; // -------------------------------------------------------- Constructors @@ -702,7 +702,7 @@ public WebConfigResourceMonitor(ServletContext servletContext, Collection u monitors.add(new Monitor(uri)); } catch (IOException ioe) { LOGGER.log(SEVERE, () -> "Unable to setup resource monitor for " + uri.toString() + ". Resource will not be monitored for changes."); - LOGGER.log(FINE, ioe, () -> ioe.toString()); + LOGGER.log(FINE, ioe, ioe::toString); } } @@ -743,7 +743,7 @@ public void run() { private class Monitor { - private URI uri; + private final URI uri; private long timestamp = -1; // ---------------------------------------------------- Constructors diff --git a/impl/src/main/java/com/sun/faces/config/FaceletsConfiguration.java b/impl/src/main/java/com/sun/faces/config/FaceletsConfiguration.java index bd7b289636..ddb6fc793a 100644 --- a/impl/src/main/java/com/sun/faces/config/FaceletsConfiguration.java +++ b/impl/src/main/java/com/sun/faces/config/FaceletsConfiguration.java @@ -36,11 +36,11 @@ public class FaceletsConfiguration { // private static final String CONSUME_COMMENTS_ATTRIBUTE_NAME = "com.sun.faces.config.ConsumeComments"; - private static Pattern EXTENSION_PATTERN = Pattern.compile("\\.[^/]+$"); + private static final Pattern EXTENSION_PATTERN = Pattern.compile("\\.[^/]+$"); - private WebConfiguration config; + private final WebConfiguration config; - private Map faceletsProcessingMappings; + private final Map faceletsProcessingMappings; public FaceletsConfiguration(WebConfiguration config) { this.config = config; diff --git a/impl/src/main/java/com/sun/faces/config/InitFacesContext.java b/impl/src/main/java/com/sun/faces/config/InitFacesContext.java index 96c3312dec..d2f88c00c5 100644 --- a/impl/src/main/java/com/sun/faces/config/InitFacesContext.java +++ b/impl/src/main/java/com/sun/faces/config/InitFacesContext.java @@ -51,7 +51,7 @@ */ public class InitFacesContext extends NoOpFacesContext { - private static Logger LOGGER = FacesLogger.CONFIG.getLogger(); + private static final Logger LOGGER = FacesLogger.CONFIG.getLogger(); private static final String INIT_FACES_CONTEXT_ATTR_NAME = RIConstants.FACES_PREFIX + "InitFacesContext"; private ServletContextAdapter servletContextAdapter; diff --git a/impl/src/main/java/com/sun/faces/config/Verifier.java b/impl/src/main/java/com/sun/faces/config/Verifier.java index dc35d7a28c..a652dce125 100644 --- a/impl/src/main/java/com/sun/faces/config/Verifier.java +++ b/impl/src/main/java/com/sun/faces/config/Verifier.java @@ -46,7 +46,7 @@ public enum ObjectType { /** * Container for any messages that may be queued. */ - private List messages; + private final List messages; // ------------------------------------------------------- Constructors diff --git a/impl/src/main/java/com/sun/faces/config/WebConfiguration.java b/impl/src/main/java/com/sun/faces/config/WebConfiguration.java index 012bb5cd16..c9021dda45 100644 --- a/impl/src/main/java/com/sun/faces/config/WebConfiguration.java +++ b/impl/src/main/java/com/sun/faces/config/WebConfiguration.java @@ -95,19 +95,19 @@ public class WebConfiguration { // Logging level. Defaults to FINE private Level loggingLevel = Level.FINE; - private Map booleanContextParameters = new EnumMap<>(BooleanWebContextInitParameter.class); + private final Map booleanContextParameters = new EnumMap<>(BooleanWebContextInitParameter.class); - private Map contextParameters = new EnumMap<>(WebContextInitParameter.class); + private final Map contextParameters = new EnumMap<>(WebContextInitParameter.class); - private Map> facesConfigParameters = new EnumMap<>(WebContextInitParameter.class); + private final Map> facesConfigParameters = new EnumMap<>(WebContextInitParameter.class); - private Map envEntries = new EnumMap<>(WebEnvironmentEntry.class); + private final Map envEntries = new EnumMap<>(WebEnvironmentEntry.class); - private Map cachedListParams; + private final Map cachedListParams; - private Set setParams = new HashSet<>(); + private final Set setParams = new HashSet<>(); - private ServletContext servletContext; + private final ServletContext servletContext; private ArrayList deferredLoggingActions; @@ -315,7 +315,7 @@ public void overrideContextInitParameter(BooleanWebContextInitParameter param, b return; } - boolean oldVal = booleanContextParameters.put(param, value); + boolean oldVal = Boolean.TRUE.equals(booleanContextParameters.put(param, value)); if (LOGGER.isLoggable(FINE) && oldVal != value) { LOGGER.log(FINE, "Overriding init parameter {0}. Changing from {1} to {2}.", new Object[] { param.getQualifiedName(), oldVal, value }); } @@ -462,8 +462,7 @@ private void discoverResourceLibraryContracts() { } } } else { - contractsToExpose = new ArrayList<>(); - contractsToExpose.addAll(foundContracts); + contractsToExpose = new ArrayList<>(foundContracts); contractMappings.put("*", contractsToExpose); } extContex.getApplicationMap().put(FaceletViewHandlingStrategy.RESOURCE_LIBRARY_CONTRACT_DATA_STRUCTURE_KEY, contractMappings); @@ -513,7 +512,7 @@ private boolean isValueValid(BooleanWebContextInitParameter param, String value) */ private void processBooleanParameters(ServletContext servletContext, String contextName) { - // process boolean contxt parameters + // process boolean context parameters for (BooleanWebContextInitParameter param : BooleanWebContextInitParameter.values()) { String strValue = servletContext.getInitParameter(param.getQualifiedName()); boolean value; @@ -534,7 +533,7 @@ private void processBooleanParameters(ServletContext servletContext, String cont if (alternate != null) { if (isValueValid(param, strValue)) { - value = Boolean.valueOf(strValue); + value = Boolean.parseBoolean(strValue); } else { value = param.getDefaultValue(); } @@ -555,7 +554,7 @@ private void processBooleanParameters(ServletContext servletContext, String cont value = param.getDefaultValue(); } else { if (isValueValid(param, strValue)) { - value = Boolean.valueOf(strValue); + value = Boolean.parseBoolean(strValue); } else { value = param.getDefaultValue(); } @@ -586,8 +585,8 @@ private void processBooleanParameters(ServletContext servletContext, String cont * @param servletContext the ServletContext of interest */ private void initSetList(ServletContext servletContext) { - for (Enumeration e = servletContext.getInitParameterNames(); e.hasMoreElements();) { - String name = e.nextElement().toString(); + for (Enumeration e = servletContext.getInitParameterNames(); e.hasMoreElements();) { + String name = e.nextElement(); if (name.startsWith("com.sun.faces") || name.startsWith("jakarta.faces")) { setParams.add(name); } @@ -677,9 +676,9 @@ private void processJndiEntries(String contextName) { initialContext = new InitialContext(); } 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(Level.WARNING, ne, () -> ne.toString()); + LOGGER.log(Level.WARNING, ne, ne::toString); } if (initialContext != null) { @@ -691,7 +690,7 @@ private void processJndiEntries(String contextName) { try { value = (String) initialContext.lookup(entryName); } catch (NamingException root) { - LOGGER.log(Level.FINE, () -> root.toString()); + LOGGER.log(Level.FINE, root::toString); } if (value != null) { @@ -778,11 +777,11 @@ public enum WebContextInitParameter { WebAppContractsDirectory(ResourceHandler.WEBAPP_CONTRACTS_DIRECTORY_PARAM_NAME, "/contracts"), ; - private String defaultValue; - private String qualifiedName; - private WebContextInitParameter alternate; - private boolean deprecated; - private DeprecationLoggingStrategy loggingStrategy; + private final String defaultValue; + private final String qualifiedName; + private final WebContextInitParameter alternate; + private final boolean deprecated; + private final DeprecationLoggingStrategy loggingStrategy; // ---------------------------------------------------------- Public Methods @@ -888,12 +887,12 @@ public enum BooleanWebContextInitParameter { UseFaceletsID("com.sun.faces.useFaceletsID",false), ; - private BooleanWebContextInitParameter alternate; + private final BooleanWebContextInitParameter alternate; - private String qualifiedName; - private boolean defaultValue; - private boolean deprecated; - private DeprecationLoggingStrategy loggingStrategy; + private final String qualifiedName; + private final boolean defaultValue; + private final boolean deprecated; + private final DeprecationLoggingStrategy loggingStrategy; // ---------------------------------------------------------- Public Methods @@ -952,7 +951,7 @@ public enum WebEnvironmentEntry { ProjectStage(jakarta.faces.application.ProjectStage.PROJECT_STAGE_JNDI_NAME); private static final String JNDI_PREFIX = "java:comp/env/"; - private String qualifiedName; + private final String qualifiedName; // ---------------------------------------------------------- Public Methods @@ -1017,10 +1016,10 @@ private interface DeferredLoggingAction { private class DeferredParameterLoggingAction implements DeferredLoggingAction { - private WebContextInitParameter parameter; - private Level loggingLevel; - private String logKey; - private Object[] params; + private final WebContextInitParameter parameter; + private final Level loggingLevel; + private final String logKey; + private final Object[] params; DeferredParameterLoggingAction(WebContextInitParameter parameter, Level loggingLevel, String logKey, Object[] params) { @@ -1047,10 +1046,10 @@ public void log() { private class DeferredBooleanParameterLoggingAction implements DeferredLoggingAction { - private BooleanWebContextInitParameter parameter; - private Level loggingLevel; - private String logKey; - private Object[] params; + private final BooleanWebContextInitParameter parameter; + private final Level loggingLevel; + private final String logKey; + private final Object[] params; DeferredBooleanParameterLoggingAction(BooleanWebContextInitParameter parameter, Level loggingLevel, String logKey, Object[] params) { this.parameter = parameter; diff --git a/impl/src/main/java/com/sun/faces/config/manager/FacesConfigInfo.java b/impl/src/main/java/com/sun/faces/config/manager/FacesConfigInfo.java index 8686434fe3..2ecf003df3 100644 --- a/impl/src/main/java/com/sun/faces/config/manager/FacesConfigInfo.java +++ b/impl/src/main/java/com/sun/faces/config/manager/FacesConfigInfo.java @@ -48,8 +48,8 @@ public class FacesConfigInfo { private static final String OTHERS = "others"; private double version = 2.0; - private boolean isWebInfFacesConfig; - private boolean metadataComplete; + private final boolean isWebInfFacesConfig; + private final boolean metadataComplete; private List absoluteOrdering; // -------------------------------------------------------- Constructors @@ -141,7 +141,7 @@ private boolean isMetadataComplete(Document document) { if (isVersionGreaterOrEqual(2.0)) { String metadataComplete = document.getDocumentElement().getAttributeNS(document.getNamespaceURI(), "metadata-complete"); - return metadataComplete != null ? Boolean.valueOf(metadataComplete) : false; + return Boolean.parseBoolean(metadataComplete); } // not a 2.0 application, so annotation processing will not occur diff --git a/impl/src/main/java/com/sun/faces/config/manager/documents/DocumentOrderingWrapper.java b/impl/src/main/java/com/sun/faces/config/manager/documents/DocumentOrderingWrapper.java index e76202de62..517ec59319 100644 --- a/impl/src/main/java/com/sun/faces/config/manager/documents/DocumentOrderingWrapper.java +++ b/impl/src/main/java/com/sun/faces/config/manager/documents/DocumentOrderingWrapper.java @@ -54,7 +54,7 @@ public class DocumentOrderingWrapper { /** * {@link Comparator} implementation to aid in sorting faces-config documents. */ - private static Comparator COMPARATOR = new DocumentOrderingComparator(); + private static final Comparator COMPARATOR = new DocumentOrderingComparator(); /** * This is the limit on the number of attempts made to sort the documents. Any attempt to exceed this limit will result @@ -105,7 +105,7 @@ public class DocumentOrderingWrapper { /** * The wrapped Document. */ - private DocumentInfo documentInfo; + private final DocumentInfo documentInfo; /** * The wrapped Document's ID. @@ -229,8 +229,7 @@ public String toString() { */ public static DocumentOrderingWrapper[] sort(DocumentOrderingWrapper[] documents, List absoluteOrder) { - List sourceList = new CopyOnWriteArrayList<>(); - sourceList.addAll(Arrays.asList(documents)); + List sourceList = new CopyOnWriteArrayList<>(Arrays.asList(documents)); List targetList = new ArrayList<>(); for (String name : absoluteOrder) { @@ -362,8 +361,8 @@ public static boolean done(DocumentOrderingWrapper[] documents, LinkedList getIds(DocumentOrderingWrapper[] documents) { LinkedList ids = new LinkedList<>(); - for (int i = 0; i < documents.length; i++) { - ids.add(documents[i].getDocumentId()); + for (DocumentOrderingWrapper document : documents) { + ids.add(document.getDocumentId()); } return ids; } @@ -377,11 +376,11 @@ public static int innerSort(DocumentOrderingWrapper[] documents) { numberOfPasses++; if (numberOfPasses == MAX_SORT_PASSED) { if (LOGGER.isLoggable(Level.SEVERE)) { - String msg = "Exceeded maximum number of attempts to sort the application's faces-config documents.\nDocument Info\n=================="; + StringBuilder msg = new StringBuilder("Exceeded maximum number of attempts to sort the application's faces-config documents.\nDocument Info\n=================="); for (DocumentOrderingWrapper w : documents) { - msg += " " + w.toString() + '\n'; + msg.append(" ").append(w.toString()).append('\n'); } - LOGGER.severe(msg); + LOGGER.severe(msg.toString()); } throw new ConfigurationException("Exceeded maximum number of attempts to sort the faces-config documents."); } @@ -447,8 +446,7 @@ private static void enhanceOrderingData(DocumentOrderingWrapper[] wrappers) thro if (OTHERS_KEY.equals(id)) { continue; } - for (int ii = 0; ii < wrappers.length; ii++) { - DocumentOrderingWrapper other = wrappers[ii]; + for (DocumentOrderingWrapper other : wrappers) { if (id.equals(other.id)) { String[] afterIds = other.getAfterIds(); if (Arrays.binarySearch(afterIds, w.id) < 0) { @@ -463,8 +461,7 @@ private static void enhanceOrderingData(DocumentOrderingWrapper[] wrappers) thro if (otherBeforeIds.length > 0) { String[] currentBeforeIds = w.getBeforeIds(); - Set newBeforeIds = new HashSet<>(); - newBeforeIds.addAll(Arrays.asList(currentBeforeIds)); + Set newBeforeIds = new HashSet<>(Arrays.asList(currentBeforeIds)); for (String bid : otherBeforeIds) { if (OTHERS_KEY.equals(bid)) { continue; @@ -488,8 +485,7 @@ private static void enhanceOrderingData(DocumentOrderingWrapper[] wrappers) thro if (OTHERS_KEY.equals(id)) { continue; } - for (int ii = 0; ii < wrappers.length; ii++) { - DocumentOrderingWrapper other = wrappers[ii]; + for (DocumentOrderingWrapper other : wrappers) { if (id.equals(other.id)) { String[] beforeIds = other.getBeforeIds(); if (Arrays.binarySearch(beforeIds, w.id) < 0) { @@ -502,8 +498,7 @@ private static void enhanceOrderingData(DocumentOrderingWrapper[] wrappers) thro String[] otherAfterIds = other.getAfterIds(); if (otherAfterIds.length > 0) { String[] currentAfterIds = w.getAfterIds(); - Set newAfterIds = new HashSet<>(); - newAfterIds.addAll(Arrays.asList(currentAfterIds)); + Set newAfterIds = new HashSet<>(Arrays.asList(currentAfterIds)); for (String bid : otherAfterIds) { if (OTHERS_KEY.equals(bid)) { continue; diff --git a/impl/src/main/java/com/sun/faces/config/manager/tasks/FindAnnotatedConfigClasses.java b/impl/src/main/java/com/sun/faces/config/manager/tasks/FindAnnotatedConfigClasses.java index 4e5bde7527..75cbaa8168 100644 --- a/impl/src/main/java/com/sun/faces/config/manager/tasks/FindAnnotatedConfigClasses.java +++ b/impl/src/main/java/com/sun/faces/config/manager/tasks/FindAnnotatedConfigClasses.java @@ -39,10 +39,10 @@ */ public class FindAnnotatedConfigClasses implements Callable, Set>>> { - private InitFacesContext facesContext; - private AnnotationProvider provider; - private ProvideMetadataToAnnotationScanTask metadataGetter; - private Set> annotatedSet; + private final InitFacesContext facesContext; + private final AnnotationProvider provider; + private final ProvideMetadataToAnnotationScanTask metadataGetter; + private final Set> annotatedSet; // -------------------------------------------------------- Constructors diff --git a/impl/src/main/java/com/sun/faces/config/manager/tasks/FindConfigResourceURIsTask.java b/impl/src/main/java/com/sun/faces/config/manager/tasks/FindConfigResourceURIsTask.java index 270578ad9b..1ebacdf514 100644 --- a/impl/src/main/java/com/sun/faces/config/manager/tasks/FindConfigResourceURIsTask.java +++ b/impl/src/main/java/com/sun/faces/config/manager/tasks/FindConfigResourceURIsTask.java @@ -37,8 +37,8 @@ */ public class FindConfigResourceURIsTask implements Callable> { - private ConfigurationResourceProvider provider; - private ServletContext servletContext; + private final ConfigurationResourceProvider provider; + private final ServletContext servletContext; // -------------------------------------------------------- Constructors @@ -63,7 +63,7 @@ public FindConfigResourceURIsTask(ConfigurationResourceProvider provider, Servle @SuppressWarnings("unchecked") @Override public Collection call() throws Exception { - Collection untypedCollection = provider.getResources(servletContext); + Collection untypedCollection = provider.getResources(servletContext); Iterator untypedCollectionIterator = untypedCollection.iterator(); Collection result = emptyList(); @@ -80,7 +80,7 @@ public Collection call() throws Exception { result.add(new URI(((URL) cur).toExternalForm())); } } else { - result = (Collection) untypedCollection; + result = untypedCollection; } } diff --git a/impl/src/main/java/com/sun/faces/config/manager/tasks/ParseConfigResourceToDOMTask.java b/impl/src/main/java/com/sun/faces/config/manager/tasks/ParseConfigResourceToDOMTask.java index 80d9fd9aac..741a69264f 100644 --- a/impl/src/main/java/com/sun/faces/config/manager/tasks/ParseConfigResourceToDOMTask.java +++ b/impl/src/main/java/com/sun/faces/config/manager/tasks/ParseConfigResourceToDOMTask.java @@ -89,10 +89,10 @@ public class ParseConfigResourceToDOMTask implements Callable { */ private static final String FACES_TO_1_1_PRIVATE_XSL = "/com/sun/faces/faces1_0-1_1toSchema.xsl"; - private ServletContext servletContext; - private URI documentURI; + private final ServletContext servletContext; + private final URI documentURI; private DocumentBuilderFactory factory; - private boolean validating; + private final boolean validating; diff --git a/impl/src/main/java/com/sun/faces/config/processor/ConverterConfigProcessor.java b/impl/src/main/java/com/sun/faces/config/processor/ConverterConfigProcessor.java index 35db5cf7bd..ec5cf41817 100644 --- a/impl/src/main/java/com/sun/faces/config/processor/ConverterConfigProcessor.java +++ b/impl/src/main/java/com/sun/faces/config/processor/ConverterConfigProcessor.java @@ -76,11 +76,11 @@ public void process(ServletContext sc, FacesContext facesContext, DocumentInfo[] // via config files take precedence processAnnotations(facesContext, FacesConverter.class); - for (int i = 0; i < documentInfos.length; i++) { + for (DocumentInfo documentInfo : documentInfos) { if (LOGGER.isLoggable(FINE)) { - LOGGER.log(FINE, format("Processing converter elements for document: ''{0}''", documentInfos[i].getSourceURI())); + LOGGER.log(FINE, format("Processing converter elements for document: ''{0}''", documentInfo.getSourceURI())); } - Document document = documentInfos[i].getDocument(); + Document document = documentInfo.getDocument(); String namespace = document.getDocumentElement().getNamespaceURI(); NodeList nodes = document.getDocumentElement().getElementsByTagNameNS(namespace, CONVERTER); if (nodes != null && nodes.getLength() > 0) { diff --git a/impl/src/main/java/com/sun/faces/config/processor/FacesConfigExtensionProcessor.java b/impl/src/main/java/com/sun/faces/config/processor/FacesConfigExtensionProcessor.java index aeaf312fbe..7357d877ae 100644 --- a/impl/src/main/java/com/sun/faces/config/processor/FacesConfigExtensionProcessor.java +++ b/impl/src/main/java/com/sun/faces/config/processor/FacesConfigExtensionProcessor.java @@ -75,17 +75,17 @@ public FacesConfigExtensionProcessor() { @Override public void process(ServletContext sc, 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 faces-config-extension elements for document: ''{0}''", documentInfos[i].getSourceURI())); + LOGGER.log(FINE, format("Processing faces-config-extension elements for document: ''{0}''", documentInfo.getSourceURI())); } - Document document = documentInfos[i].getDocument(); + Document document = documentInfo.getDocument(); String namespace = document.getDocumentElement().getNamespaceURI(); NodeList facesConfigExtensions = document.getDocumentElement().getElementsByTagNameNS(namespace, FACES_CONFIG_EXTENSION); if (facesConfigExtensions != null && facesConfigExtensions.getLength() > 0) { - processFacesConfigExtensions(facesConfigExtensions, namespace, documentInfos[i]); + processFacesConfigExtensions(facesConfigExtensions, namespace, documentInfo); } } diff --git a/impl/src/main/java/com/sun/faces/config/processor/LifecycleConfigProcessor.java b/impl/src/main/java/com/sun/faces/config/processor/LifecycleConfigProcessor.java index 939a4a49fe..fbb3157b21 100644 --- a/impl/src/main/java/com/sun/faces/config/processor/LifecycleConfigProcessor.java +++ b/impl/src/main/java/com/sun/faces/config/processor/LifecycleConfigProcessor.java @@ -61,7 +61,7 @@ public class LifecycleConfigProcessor extends AbstractConfigProcessor { *

*/ private static final String PHASE_LISTENER = "phase-listener"; - private List appPhaseListeners; + private final List appPhaseListeners; public LifecycleConfigProcessor() { appPhaseListeners = new CopyOnWriteArrayList<>(); @@ -73,12 +73,12 @@ public LifecycleConfigProcessor() { public void process(ServletContext servletContext, FacesContext facesContext, DocumentInfo[] documentInfos) throws Exception { LifecycleFactory factory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); - for (int i = 0; i < documentInfos.length; i++) { + for (DocumentInfo documentInfo : documentInfos) { if (LOGGER.isLoggable(FINE)) { - LOGGER.log(FINE, format("Processing lifecycle elements for document: ''{0}''", documentInfos[i].getSourceURI())); + LOGGER.log(FINE, format("Processing lifecycle elements for document: ''{0}''", documentInfo.getSourceURI())); } - Document document = documentInfos[i].getDocument(); + Document document = documentInfo.getDocument(); String namespace = document.getDocumentElement().getNamespaceURI(); NodeList lifecycles = document.getElementsByTagNameNS(namespace, LIFECYCLE); diff --git a/impl/src/main/java/com/sun/faces/context/AjaxNoAjaxExceptionHandler.java b/impl/src/main/java/com/sun/faces/context/AjaxNoAjaxExceptionHandler.java index c397d3a113..b1690966ac 100644 --- a/impl/src/main/java/com/sun/faces/context/AjaxNoAjaxExceptionHandler.java +++ b/impl/src/main/java/com/sun/faces/context/AjaxNoAjaxExceptionHandler.java @@ -22,7 +22,7 @@ public class AjaxNoAjaxExceptionHandler extends ExceptionHandlerWrapper { - private AjaxExceptionHandlerImpl ajaxExceptionHandlerImpl; + private final AjaxExceptionHandlerImpl ajaxExceptionHandlerImpl; public AjaxNoAjaxExceptionHandler(AjaxExceptionHandlerImpl ajaxExceptionHandlerImpl, ExceptionHandlerImpl exceptionHandlerImpl) { super(exceptionHandlerImpl); diff --git a/impl/src/main/java/com/sun/faces/context/ExceptionHandlerImpl.java b/impl/src/main/java/com/sun/faces/context/ExceptionHandlerImpl.java index 708ef57385..551c6b9961 100644 --- a/impl/src/main/java/com/sun/faces/context/ExceptionHandlerImpl.java +++ b/impl/src/main/java/com/sun/faces/context/ExceptionHandlerImpl.java @@ -56,7 +56,7 @@ public class ExceptionHandlerImpl extends ExceptionHandler { private LinkedList unhandledExceptions; private LinkedList handledExceptions; private ExceptionQueuedEvent handled; - private boolean errorPagePresent; + private final boolean errorPagePresent; // ------------------------------------------------------------ Constructors @@ -209,7 +209,7 @@ private void throwIt(FacesContext ctx, FacesException fe) { LOGGER.log(Level.INFO, "Exception when handling error trying to reset the response.", wrapped); } } - if (null != wrapped && wrapped instanceof FacesFileNotFoundException) { + if (wrapped instanceof FacesFileNotFoundException) { extContext.setResponseStatus(404); } else { extContext.setResponseStatus(500); @@ -225,7 +225,7 @@ private void throwIt(FacesContext ctx, FacesException fe) { if (isDevelopment) { // store the view root where the exception occurred into the // request scope so that the error page can display that component - // tree and not the one rendering the errorpage + // tree and not the one rendering the error page ctx.getExternalContext().getRequestMap().put("com.sun.faces.error.view", ctx.getViewRoot()); } throw fe; diff --git a/impl/src/main/java/com/sun/faces/context/PartialViewContextImpl.java b/impl/src/main/java/com/sun/faces/context/PartialViewContextImpl.java index 2d650e03cf..6fc2bad1aa 100644 --- a/impl/src/main/java/com/sun/faces/context/PartialViewContextImpl.java +++ b/impl/src/main/java/com/sun/faces/context/PartialViewContextImpl.java @@ -65,7 +65,7 @@ public class PartialViewContextImpl extends PartialViewContext { // Log instance for this class - private static Logger LOGGER = FacesLogger.CONTEXT.getLogger(); + private static final Logger LOGGER = FacesLogger.CONTEXT.getLogger(); private boolean released; @@ -161,7 +161,7 @@ public void setRenderAll(boolean renderAll) { @Override public boolean isResetValues() { Object value = PARTIAL_RESET_VALUES_PARAM.getValue(ctx); - return null != value && "true".equals(value) ? true : false; + return Boolean.TRUE.toString().equals(value); } @Override @@ -564,8 +564,8 @@ private void assertNotReleased() { private static class PhaseAwareVisitCallback implements VisitCallback { - private PhaseId curPhase; - private FacesContext ctx; + private final PhaseId curPhase; + private final FacesContext ctx; private PhaseAwareVisitCallback(FacesContext ctx, PhaseId curPhase) { this.ctx = ctx; @@ -620,7 +620,7 @@ public VisitResult visit(VisitContext context, UIComponent comp) { private static final class DelayedInitPartialResponseWriter extends PartialResponseWriter { private ResponseWriter writer; - private PartialViewContextImpl ctx; + private final PartialViewContextImpl ctx; // -------------------------------------------------------- Constructors diff --git a/impl/src/main/java/com/sun/faces/context/StringArrayValuesMap.java b/impl/src/main/java/com/sun/faces/context/StringArrayValuesMap.java index 07293ff87d..5401eafd8e 100644 --- a/impl/src/main/java/com/sun/faces/context/StringArrayValuesMap.java +++ b/impl/src/main/java/com/sun/faces/context/StringArrayValuesMap.java @@ -36,11 +36,11 @@ public boolean containsValue(Object value) { return false; } - Set entrySet = entrySet(); - for (Object anEntrySet : entrySet) { - Map.Entry entry = (Map.Entry) anEntrySet; + Set> entrySet = entrySet(); + for (Map.Entry entry : entrySet) { + // values will be arrays - if (Arrays.equals((Object[]) value, (Object[]) entry.getValue())) { + if (Arrays.equals((Object[]) value, entry.getValue())) { return true; } } @@ -89,10 +89,9 @@ public int hashCode() { protected int hashCode(Object someObject) { int hashCode = 7 * someObject.hashCode(); - for (Object o : entrySet()) { - Map.Entry entry = (Map.Entry) o; + for (Map.Entry entry : entrySet()) { hashCode += entry.getKey().hashCode(); - hashCode += Arrays.hashCode((Object[]) entry.getValue()); + hashCode += Arrays.hashCode(entry.getValue()); } return hashCode; } diff --git a/impl/src/main/java/com/sun/faces/context/flash/ELFlash.java b/impl/src/main/java/com/sun/faces/context/flash/ELFlash.java index 85a728229f..a85cf21975 100644 --- a/impl/src/main/java/com/sun/faces/context/flash/ELFlash.java +++ b/impl/src/main/java/com/sun/faces/context/flash/ELFlash.java @@ -116,7 +116,7 @@ public class ELFlash extends Flash { private final boolean distributable; - private ByteArrayGuardAESCTR guard; + private final ByteArrayGuardAESCTR guard; // @@ -315,7 +315,7 @@ public boolean isKeepMessages() { @Override public void setKeepMessages(boolean newValue) { - loggingGetPhaseMapForWriting(false).put(CONSTANTS.KeepAllMessagesAttributeName.toString(), Boolean.valueOf(newValue)); + loggingGetPhaseMapForWriting(false).put(CONSTANTS.KeepAllMessagesAttributeName.toString(), newValue); } diff --git a/impl/src/main/java/com/sun/faces/el/CompositeComponentAttributesELResolver.java b/impl/src/main/java/com/sun/faces/el/CompositeComponentAttributesELResolver.java index 6609db3803..4cb5b2d839 100644 --- a/impl/src/main/java/com/sun/faces/el/CompositeComponentAttributesELResolver.java +++ b/impl/src/main/java/com/sun/faces/el/CompositeComponentAttributesELResolver.java @@ -89,7 +89,7 @@ public Object getValue(ELContext context, Object base, Object property) { notNull("context", context); - if (base != null && base instanceof UIComponent && UIComponent.isCompositeComponent((UIComponent) base) && property != null) { + if (base instanceof UIComponent && UIComponent.isCompositeComponent((UIComponent) base) && property != null) { String propertyName = property.toString(); if (COMPOSITE_COMPONENT_ATTRIBUTES_NAME.equals(propertyName)) { @@ -271,11 +271,11 @@ public Map getEvalMapFor(UIComponent c, FacesContext ctx) { */ private static final class ExpressionEvalMap implements Map, CompositeComponentExpressionHolder { - private Map attributesMap; + private final Map attributesMap; private PropertyDescriptor[] declaredAttributes; private Map declaredDefaultValues; private FacesContext ctx; - private UIComponent cc; + private final UIComponent cc; // -------------------------------------------------------- Constructors @@ -335,7 +335,7 @@ public Object get(Object key) { return ((ValueExpression) v).getValue(ctx.getELContext()); } } - if (v != null && v instanceof MethodExpression) { + if (v instanceof MethodExpression) { return v; } return v; @@ -343,7 +343,7 @@ public Object get(Object key) { @Override public Object put(String key, Object value) { - // Unlinke AttributesMap.get() which will obtain a value from + // Unlike AttributesMap.get() which will obtain a value from // a ValueExpression, AttributesMap.put(), when passed a value, // will never call ValueExpression.setValue(), so we have to take // matters into our own hands... diff --git a/impl/src/main/java/com/sun/faces/el/ELContextImpl.java b/impl/src/main/java/com/sun/faces/el/ELContextImpl.java index 723c75b779..84e4c5d47b 100644 --- a/impl/src/main/java/com/sun/faces/el/ELContextImpl.java +++ b/impl/src/main/java/com/sun/faces/el/ELContextImpl.java @@ -43,7 +43,7 @@ public class ELContextImpl extends ELContext { private FunctionMapper functionMapper = new NoopFunctionMapper(); private VariableMapper variableMapper; - private ELResolver resolver; + private final ELResolver resolver; // ------------------------------------------------------------ Constructors @@ -66,7 +66,7 @@ public ELContextImpl(FacesContext facesContext) { putContext(ExpressionFactory.class, expressionFactory); } - if (facesContext instanceof InitFacesContext == false) { + if (!(facesContext instanceof InitFacesContext)) { UIViewRoot root = facesContext.getViewRoot(); if (root != null) { setLocale(root.getLocale()); @@ -104,7 +104,7 @@ public void setFunctionMapper(FunctionMapper functionMapper) { private static class VariableMapperImpl extends VariableMapper { - private Map variables; + private final Map variables; public VariableMapperImpl() { variables = new HashMap<>(); diff --git a/impl/src/main/java/com/sun/faces/renderkit/AttributeManager.java b/impl/src/main/java/com/sun/faces/renderkit/AttributeManager.java index 091d63e887..28d3113a7f 100644 --- a/impl/src/main/java/com/sun/faces/renderkit/AttributeManager.java +++ b/impl/src/main/java/com/sun/faces/renderkit/AttributeManager.java @@ -40,7 +40,7 @@ public enum Key { OUTPUTBODY, OUTPUTDOCTYPE, OUTPUTHEAD; } - private static Map ATTRIBUTE_LOOKUP = CollectionsUtils.map() + private static final Map ATTRIBUTE_LOOKUP = CollectionsUtils.map() .add(Key.COMMANDBUTTON, ar(attr("accesskey"), attr("dir"), attr("lang"), attr("onblur", "blur"), attr("onchange", "change"), attr("ondblclick", "dblclick"), attr("onfocus", "focus"), attr("onkeydown", "keydown"), attr("onkeypress", "keypress"), attr("onkeyup", "keyup"), diff --git a/impl/src/main/java/com/sun/faces/util/ComponentStruct.java b/impl/src/main/java/com/sun/faces/util/ComponentStruct.java index f2d7ab5a81..752afc40b8 100644 --- a/impl/src/main/java/com/sun/faces/util/ComponentStruct.java +++ b/impl/src/main/java/com/sun/faces/util/ComponentStruct.java @@ -73,7 +73,7 @@ public void restoreState(FacesContext ctx, Object state) { return; } - Object s[] = (Object[]) state; + Object[] s = (Object[]) state; action = (String) s[0]; parentClientId = (String) s[1]; clientId = (String) s[2]; @@ -87,7 +87,7 @@ public Object saveState(FacesContext ctx) { throw new NullPointerException(); } - Object state[] = new Object[5]; + Object[] state = new Object[5]; state[0] = action; state[1] = parentClientId; state[2] = clientId; diff --git a/impl/src/main/java/com/sun/faces/util/FacesLogger.java b/impl/src/main/java/com/sun/faces/util/FacesLogger.java index 341aef0c46..446018c7f1 100644 --- a/impl/src/main/java/com/sun/faces/util/FacesLogger.java +++ b/impl/src/main/java/com/sun/faces/util/FacesLogger.java @@ -38,7 +38,7 @@ public enum FacesLogger { private static final String LOGGER_RESOURCES = "com.sun.faces.LogStrings"; public static final String FACES_LOGGER_NAME_PREFIX = "jakarta.enterprise.resource.webcontainer.faces."; - private String loggerName; + private final String loggerName; FacesLogger(String loggerName) { this.loggerName = FACES_LOGGER_NAME_PREFIX + loggerName; diff --git a/impl/src/main/java/com/sun/faces/util/LRUMap.java b/impl/src/main/java/com/sun/faces/util/LRUMap.java index dc14511294..82521b304f 100644 --- a/impl/src/main/java/com/sun/faces/util/LRUMap.java +++ b/impl/src/main/java/com/sun/faces/util/LRUMap.java @@ -25,7 +25,7 @@ public class LRUMap extends LinkedHashMap { private static final long serialVersionUID = -7137951139094651602L; - private int maxCapacity; + private final int maxCapacity; // ------------------------------------------------------------ Constructors diff --git a/impl/src/main/java/com/sun/faces/util/MessageFactory.java b/impl/src/main/java/com/sun/faces/util/MessageFactory.java index 1e907b6f71..25ff928ddd 100644 --- a/impl/src/main/java/com/sun/faces/util/MessageFactory.java +++ b/impl/src/main/java/com/sun/faces/util/MessageFactory.java @@ -237,7 +237,7 @@ protected static Application getApplication() { return afactory.getApplication(); } - protected static ClassLoader getCurrentLoader(Class fallbackClass) { + protected static ClassLoader getCurrentLoader(Class fallbackClass) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); if (loader == null) { loader = fallbackClass.getClassLoader(); @@ -319,8 +319,8 @@ private String getFormattedString(String msgtext, Object[] params) { return localizedStr; } - private Locale locale; - private Object[] parameters; + private final Locale locale; + private final Object[] parameters; private Object[] resolvedParameters; } diff --git a/impl/src/main/java/com/sun/faces/util/MetadataWrapperMap.java b/impl/src/main/java/com/sun/faces/util/MetadataWrapperMap.java index ca5df63edf..06876270e8 100644 --- a/impl/src/main/java/com/sun/faces/util/MetadataWrapperMap.java +++ b/impl/src/main/java/com/sun/faces/util/MetadataWrapperMap.java @@ -32,8 +32,8 @@ protected Map> getMetadata() { return metadata; } - private Map wrapped; - private Map> metadata; + private final Map wrapped; + private final Map> metadata; @Override public void clear() { diff --git a/impl/src/main/java/com/sun/faces/util/ScopedRunner.java b/impl/src/main/java/com/sun/faces/util/ScopedRunner.java index 25645a0270..b5ab0de7bb 100644 --- a/impl/src/main/java/com/sun/faces/util/ScopedRunner.java +++ b/impl/src/main/java/com/sun/faces/util/ScopedRunner.java @@ -30,9 +30,9 @@ */ public class ScopedRunner { - private FacesContext context; - private Map scopedVariables; - private Map previousVariables = new HashMap<>(); + private final FacesContext context; + private final Map scopedVariables; + private final Map previousVariables = new HashMap<>(); public ScopedRunner(FacesContext context) { this(context, new HashMap<>()); diff --git a/impl/src/main/java/com/sun/faces/vendor/WebContainerInjectionProvider.java b/impl/src/main/java/com/sun/faces/vendor/WebContainerInjectionProvider.java index aa563c211c..68e9c88951 100644 --- a/impl/src/main/java/com/sun/faces/vendor/WebContainerInjectionProvider.java +++ b/impl/src/main/java/com/sun/faces/vendor/WebContainerInjectionProvider.java @@ -47,7 +47,7 @@ public class WebContainerInjectionProvider implements InjectionProvider { private static final Logger LOGGER = FacesLogger.APPLICATION.getLogger(); - private static Map, ConcurrentHashMap, MethodHolder>> methodsPerClazz = new ConcurrentHashMap<>(); + private static final Map, ConcurrentHashMap, MethodHolder>> methodsPerClazz = new ConcurrentHashMap<>(); // ------------------------------------------ Methods from InjectionProvider @@ -74,7 +74,7 @@ public void invokePostConstruct(Object managedBean) throws InjectionProviderExce private static void invokeAnnotatedMethod(Method method, Object managedBean) throws InjectionProviderException { if (method != null) { - boolean accessible = method.isAccessible(); + boolean accessible = method.canAccess(managedBean); method.setAccessible(true); try { diff --git a/impl/src/main/java/jakarta/faces/CurrentThreadToServletContext.java b/impl/src/main/java/jakarta/faces/CurrentThreadToServletContext.java index 4f02188633..a100fb7bcc 100644 --- a/impl/src/main/java/jakarta/faces/CurrentThreadToServletContext.java +++ b/impl/src/main/java/jakarta/faces/CurrentThreadToServletContext.java @@ -23,6 +23,7 @@ import static java.lang.System.identityHashCode; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -39,8 +40,8 @@ final class CurrentThreadToServletContext { private final ServletContextFacesContextFactory servletContextFacesContextFactory = new ServletContextFacesContextFactory(); ConcurrentMap factoryFinderMap = new ConcurrentHashMap<>(); - private AtomicBoolean logNullFacesContext = new AtomicBoolean(); - private AtomicBoolean logNonNullFacesContext = new AtomicBoolean(); + private final AtomicBoolean logNullFacesContext = new AtomicBoolean(); + private final AtomicBoolean logNonNullFacesContext = new AtomicBoolean(); // ------------------------------------------------------ Public Methods @@ -336,11 +337,11 @@ public boolean equals(Object obj) { } final FactoryFinderCacheKey other = (FactoryFinderCacheKey) obj; - if (classLoader != other.classLoader && (classLoader == null || !classLoader.equals(other.classLoader))) { + if (!Objects.equals(classLoader, other.classLoader)) { return false; } - if (marker != other.marker && (marker == null || !marker.equals(other.marker))) { + if (!Objects.equals(marker, other.marker)) { return false; } diff --git a/impl/src/main/java/jakarta/faces/application/NavigationCaseWrapper.java b/impl/src/main/java/jakarta/faces/application/NavigationCaseWrapper.java index 2883d9c34a..64b461b6f0 100644 --- a/impl/src/main/java/jakarta/faces/application/NavigationCaseWrapper.java +++ b/impl/src/main/java/jakarta/faces/application/NavigationCaseWrapper.java @@ -40,7 +40,7 @@ */ public abstract class NavigationCaseWrapper extends NavigationCase implements FacesWrapper { - private NavigationCase wrapped; + private final NavigationCase wrapped; /** * @deprecated Use the other constructor taking the implementation being wrapped. diff --git a/impl/src/main/java/jakarta/faces/application/StateManagerWrapper.java b/impl/src/main/java/jakarta/faces/application/StateManagerWrapper.java index 26d56271da..72034ad9a1 100644 --- a/impl/src/main/java/jakarta/faces/application/StateManagerWrapper.java +++ b/impl/src/main/java/jakarta/faces/application/StateManagerWrapper.java @@ -37,7 +37,7 @@ */ public abstract class StateManagerWrapper extends StateManager implements FacesWrapper { - private StateManager wrapped; + private final StateManager wrapped; /** *

diff --git a/impl/src/main/java/jakarta/faces/component/ComponentStateHelper.java b/impl/src/main/java/jakarta/faces/component/ComponentStateHelper.java index 931f6643b7..1eda497160 100644 --- a/impl/src/main/java/jakarta/faces/component/ComponentStateHelper.java +++ b/impl/src/main/java/jakarta/faces/component/ComponentStateHelper.java @@ -44,10 +44,10 @@ @SuppressWarnings({ "unchecked" }) class ComponentStateHelper implements StateHelper, TransientStateHelper { - private UIComponent component; + private final UIComponent component; private boolean isTransient; - private Map deltaMap; - private Map defaultMap; + private final Map deltaMap; + private final Map defaultMap; private Map transientState; // ------------------------------------------------------------ Constructors @@ -349,7 +349,7 @@ private void handleAttribute(String name, Object value) { List setAttributes = (List) component.getAttributes().get("jakarta.faces.component.UIComponentBase.attributesThatAreSet"); if (setAttributes == null) { String className = getClass().getName(); - if (className != null && className.startsWith("jakarta.faces.component.")) { + if (className.startsWith("jakarta.faces.component.")) { setAttributes = new ArrayList<>(6); component.getAttributes().put("jakarta.faces.component.UIComponentBase.attributesThatAreSet", setAttributes); } diff --git a/impl/src/main/java/jakarta/faces/component/MessageFactory.java b/impl/src/main/java/jakarta/faces/component/MessageFactory.java index 367ce62fc7..a01feeb4bb 100644 --- a/impl/src/main/java/jakarta/faces/component/MessageFactory.java +++ b/impl/src/main/java/jakarta/faces/component/MessageFactory.java @@ -317,8 +317,8 @@ private String getFormattedString(String msgtext, Object[] params) { return localizedStr; } - private Locale locale; - private Object[] parameters; + private final Locale locale; + private final Object[] parameters; private Object[] resolvedParameters; } diff --git a/impl/src/main/java/jakarta/faces/component/SelectItemsIterator.java b/impl/src/main/java/jakarta/faces/component/SelectItemsIterator.java index 47ba51c16f..f7a2637715 100644 --- a/impl/src/main/java/jakarta/faces/component/SelectItemsIterator.java +++ b/impl/src/main/java/jakarta/faces/component/SelectItemsIterator.java @@ -70,7 +70,7 @@ public SelectItemsIterator(FacesContext ctx, UIComponent parent) { * Iterator over the children of the parent component. *

*/ - private ListIterator kids; + private final ListIterator kids; /** * Expose single SelectItems via an Iterator. This iterator will be reset/reused for each individual SelectItem instance @@ -81,7 +81,7 @@ public SelectItemsIterator(FacesContext ctx, UIComponent parent) { /** * The {@link FacesContext} for the current request. */ - private FacesContext ctx; + private final FacesContext ctx; // -------------------------------------------------------- Iterator Methods @@ -274,8 +274,8 @@ private void updateItem(SelectItem item) { */ private static final class MapIterator implements Iterator { - private SelectItem item = new SelectItem(); - private Iterator iterator; + private final SelectItem item = new SelectItem(); + private final Iterator iterator; // -------------------------------------------------------- Constructors @@ -403,9 +403,9 @@ private static final class GenericObjectSelectItem extends SelectItem { /** * The request-scoped variable under which the current object will be exposed. */ - private String var; + private final String var; - private UISelectItems sourceComponent; + private final UISelectItems sourceComponent; // -------------------------------------------------------- Constructors @@ -489,9 +489,9 @@ private void readObject(ObjectInputStream in) throws IOException { */ private static final class ArrayIterator extends GenericObjectSelectItemIterator { - private FacesContext ctx; - private Object array; - private int count; + private final FacesContext ctx; + private final Object array; + private final int count; private int index; // -------------------------------------------------------- Constructors @@ -545,8 +545,8 @@ public void remove() { */ private static final class IterableItemIterator extends GenericObjectSelectItemIterator { - private FacesContext ctx; - private Iterator iterator; + private final FacesContext ctx; + private final Iterator iterator; // -------------------------------------------------------- Constructors diff --git a/impl/src/main/java/jakarta/faces/component/UIComponentBase.java b/impl/src/main/java/jakarta/faces/component/UIComponentBase.java index 8ccbfee967..8b660b0634 100644 --- a/impl/src/main/java/jakarta/faces/component/UIComponentBase.java +++ b/impl/src/main/java/jakarta/faces/component/UIComponentBase.java @@ -102,7 +102,7 @@ public abstract class UIComponentBase extends UIComponent { // -------------------------------------------------------------- Attributes - private static Logger LOGGER = Logger.getLogger("jakarta.faces.component", "jakarta.faces.LogStrings"); + private static final Logger LOGGER = Logger.getLogger("jakarta.faces.component", "jakarta.faces.LogStrings"); private static final String ADDED = UIComponentBase.class.getName() + ".ADDED"; diff --git a/impl/src/main/java/jakarta/faces/component/UIData.java b/impl/src/main/java/jakarta/faces/component/UIData.java index 6180c7b5da..099e765145 100644 --- a/impl/src/main/java/jakarta/faces/component/UIData.java +++ b/impl/src/main/java/jakarta/faces/component/UIData.java @@ -2371,8 +2371,8 @@ public WrapperEvent(UIComponent component, FacesEvent event, int rowIndex) { this.rowIndex = rowIndex; } - private FacesEvent event = null; - private int rowIndex = -1; + private final FacesEvent event; + private final int rowIndex; public FacesEvent getFacesEvent() { return event; diff --git a/impl/src/main/java/jakarta/faces/component/UINamingContainer.java b/impl/src/main/java/jakarta/faces/component/UINamingContainer.java index 8c00a87708..668561ba92 100644 --- a/impl/src/main/java/jakarta/faces/component/UINamingContainer.java +++ b/impl/src/main/java/jakarta/faces/component/UINamingContainer.java @@ -39,7 +39,7 @@ public class UINamingContainer extends UIComponentBase implements NamingContaine // ------------------------------------------------------ Manifest Constants - private static Logger LOGGER = Logger.getLogger("jakarta.faces.component", "jakarta.faces.LogStrings"); + private static final Logger LOGGER = Logger.getLogger("jakarta.faces.component", "jakarta.faces.LogStrings"); /** *

diff --git a/impl/src/main/java/jakarta/faces/component/UIViewAction.java b/impl/src/main/java/jakarta/faces/component/UIViewAction.java index 9157db0f8a..22ffdd6bb9 100644 --- a/impl/src/main/java/jakarta/faces/component/UIViewAction.java +++ b/impl/src/main/java/jakarta/faces/component/UIViewAction.java @@ -320,7 +320,7 @@ public void addActionListener(final ActionListener listener) { */ @Override public ActionListener[] getActionListeners() { - ActionListener al[] = (ActionListener[]) getFacesListeners(ActionListener.class); + ActionListener[] al = (ActionListener[]) getFacesListeners(ActionListener.class); return al; } @@ -638,7 +638,7 @@ private UIViewRoot getViewRootOf(final FacesEvent e) { * A FacesContext delegator that gives us the necessary controls over the FacesContext to allow the execution of the * lifecycle to accomodate the UIViewAction sequence. */ - private class InstrumentedFacesContext extends FacesContextWrapper { + private static class InstrumentedFacesContext extends FacesContextWrapper { private boolean viewRootCleared = false; private boolean renderedResponseControlDisabled = false; diff --git a/impl/src/main/java/jakarta/faces/component/UIViewParameter.java b/impl/src/main/java/jakarta/faces/component/UIViewParameter.java index 884efd94f4..517f2cffa4 100644 --- a/impl/src/main/java/jakarta/faces/component/UIViewParameter.java +++ b/impl/src/main/java/jakarta/faces/component/UIViewParameter.java @@ -459,9 +459,9 @@ private boolean hasValueExpression() { public static class Reference { - private StateHolderSaver saver; - private int indexInParent; - private String viewIdAtTimeOfConstruction; + private final StateHolderSaver saver; + private final int indexInParent; + private final String viewIdAtTimeOfConstruction; /** *

diff --git a/impl/src/main/java/jakarta/faces/component/UpdateModelException.java b/impl/src/main/java/jakarta/faces/component/UpdateModelException.java index 6a7ffa4be3..0a152e0c10 100644 --- a/impl/src/main/java/jakarta/faces/component/UpdateModelException.java +++ b/impl/src/main/java/jakarta/faces/component/UpdateModelException.java @@ -33,7 +33,7 @@ public class UpdateModelException extends FacesException { private static final long serialVersionUID = 6081145672680351218L; - private FacesMessage facesMessage; + private final FacesMessage facesMessage; // ------------------------------------------------------------ Constructors diff --git a/impl/src/main/java/jakarta/faces/component/behavior/ClientBehaviorContext.java b/impl/src/main/java/jakarta/faces/component/behavior/ClientBehaviorContext.java index a5a0ad8c8d..8a58507dcd 100644 --- a/impl/src/main/java/jakarta/faces/component/behavior/ClientBehaviorContext.java +++ b/impl/src/main/java/jakarta/faces/component/behavior/ClientBehaviorContext.java @@ -18,6 +18,7 @@ import java.util.Collection; import java.util.Collections; +import java.util.Objects; import jakarta.faces.component.UIComponent; import jakarta.faces.context.FacesContext; @@ -137,33 +138,24 @@ public static ClientBehaviorContext createClientBehaviorContext(FacesContext con // Little static member class that provides a default implementation private static final class ClientBehaviorContextImpl extends ClientBehaviorContext { - private FacesContext context; - private UIComponent component; - private String eventName; - private String sourceId; - private Collection parameters; + private final FacesContext context; + private final UIComponent component; + private final String eventName; + private final String sourceId; + private final Collection parameters; private ClientBehaviorContextImpl(FacesContext context, UIComponent component, String eventName, String sourceId, Collection parameters) { - if (null == context) { - throw new NullPointerException(); - } - - if (null == component) { - throw new NullPointerException(); - } - - if (null == eventName) { - throw new NullPointerException(); - } + Objects.requireNonNull(context); + Objects.requireNonNull(component); + Objects.requireNonNull(eventName); this.context = context; this.component = component; this.eventName = eventName; this.sourceId = sourceId; - - this.parameters = parameters == null ? Collections.emptyList() : parameters; + this.parameters = parameters == null ? Collections.emptyList() : parameters; } @Override @@ -203,8 +195,8 @@ public Collection getParameters() { */ public static class Parameter { - private String name; - private Object value; + private final String name; + private final Object value; /** *

diff --git a/impl/src/main/java/jakarta/faces/component/visit/VisitContext.java b/impl/src/main/java/jakarta/faces/component/visit/VisitContext.java index 33d5ef7e76..7556a5f1db 100644 --- a/impl/src/main/java/jakarta/faces/component/visit/VisitContext.java +++ b/impl/src/main/java/jakarta/faces/component/visit/VisitContext.java @@ -75,7 +75,7 @@ abstract public class VisitContext { // Note: We cannot use Collections.emptyList() as that returns // a shared instance - we want to unique instance to allow for // identity tests. - static public final Collection ALL_IDS = new AbstractCollection() { + static public final Collection ALL_IDS = new AbstractCollection<>() { @Override public Iterator iterator() { diff --git a/impl/src/main/java/jakarta/faces/context/FacesContext.java b/impl/src/main/java/jakarta/faces/context/FacesContext.java index 4f034cb69c..acb0e3edc1 100644 --- a/impl/src/main/java/jakarta/faces/context/FacesContext.java +++ b/impl/src/main/java/jakarta/faces/context/FacesContext.java @@ -23,6 +23,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import com.sun.faces.config.InitFacesContext; import jakarta.el.ELContext; import jakarta.faces.FactoryFinder; import jakarta.faces.application.Application; @@ -62,8 +63,8 @@ public abstract class FacesContext { private boolean processingEvents = true; private boolean isCreatedFromValidFactory = true; - private static ConcurrentHashMap threadInitContext = new ConcurrentHashMap(2); - private static ConcurrentHashMap initContextServletContext = new ConcurrentHashMap(2); + private static final ConcurrentHashMap threadInitContext = new ConcurrentHashMap<>(2); + private static final ConcurrentHashMap initContextServletContext = new ConcurrentHashMap<>(2); /** * Default constructor. @@ -74,19 +75,16 @@ public abstract class FacesContext { public FacesContext() { Thread curThread = Thread.currentThread(); StackTraceElement[] callstack = curThread.getStackTrace(); - if (null != callstack) { - String declaringClassName = callstack[3].getClassName(); - try { - ClassLoader curLoader = curThread.getContextClassLoader(); - Class declaringClass = curLoader.loadClass(declaringClassName); - if (!FacesContextFactory.class.isAssignableFrom(declaringClass)) { - isCreatedFromValidFactory = false; - } - } catch (ClassNotFoundException cnfe) { - + String declaringClassName = callstack[3].getClassName(); + try { + ClassLoader curLoader = curThread.getContextClassLoader(); + Class declaringClass = curLoader.loadClass(declaringClassName); + if (!FacesContextFactory.class.isAssignableFrom(declaringClass)) { + isCreatedFromValidFactory = false; } - } + } catch (ClassNotFoundException ignored) { + } } // -------------------------------------------------------------- Properties @@ -838,12 +836,7 @@ public boolean isProjectStage(ProjectStage stage) { * The ThreadLocal variable used to record the {@link FacesContext} instance for each processing thread. *

*/ - private static ThreadLocal instance = new ThreadLocal<>() { - @Override - protected FacesContext initialValue() { - return null; - } - }; + private static final ThreadLocal instance = ThreadLocal.withInitial(() -> null); /** *

@@ -859,7 +852,7 @@ public static FacesContext getCurrentInstance() { FacesContext facesContext = instance.get(); if (null == facesContext) { - facesContext = (FacesContext) threadInitContext.get(Thread.currentThread()); + facesContext = threadInitContext.get(Thread.currentThread()); } // Bug 20458755: If not found in the threadInitContext, use // a special FacesContextFactory implementation that knows how to diff --git a/impl/src/main/java/jakarta/faces/context/ResponseWriter.java b/impl/src/main/java/jakarta/faces/context/ResponseWriter.java index f8c46f7352..b7dabf41f0 100644 --- a/impl/src/main/java/jakarta/faces/context/ResponseWriter.java +++ b/impl/src/main/java/jakarta/faces/context/ResponseWriter.java @@ -311,7 +311,7 @@ public void writeText(Object text, UIComponent component, String property) throw * @throws IOException if an input/output error occurs * @throws NullPointerException if text is null */ - public abstract void writeText(char text[], int off, int len) throws IOException; + public abstract void writeText(char[] text, int off, int len) throws IOException; /** *

diff --git a/impl/src/main/java/jakarta/faces/event/ExceptionQueuedEventContext.java b/impl/src/main/java/jakarta/faces/event/ExceptionQueuedEventContext.java index f840d8bb10..297401eb5d 100644 --- a/impl/src/main/java/jakarta/faces/event/ExceptionQueuedEventContext.java +++ b/impl/src/main/java/jakarta/faces/event/ExceptionQueuedEventContext.java @@ -53,10 +53,10 @@ public class ExceptionQueuedEventContext implements SystemEventListenerHolder { */ public static final String IN_AFTER_PHASE_KEY = ExceptionQueuedEventContext.class.getName() + ".IN_AFTER_PHASE"; - private FacesContext context; - private Throwable thrown; - private UIComponent component; - private PhaseId phaseId; + private final FacesContext context; + private final Throwable thrown; + private final UIComponent component; + private final PhaseId phaseId; private Map attributes; private List listener; @@ -221,10 +221,9 @@ public Map getAttributes() { public List getListenersForEventClass(Class facesEventClass) { if (null == listener) { - List list = new ArrayList<>(1); - list.add(context.getExceptionHandler()); - listener = Collections.unmodifiableList(list); + listener = List.of(context.getExceptionHandler()); } + return listener; } diff --git a/impl/src/main/java/jakarta/faces/event/PhaseEvent.java b/impl/src/main/java/jakarta/faces/event/PhaseEvent.java index 27a95e70a4..4b0d7f5440 100644 --- a/impl/src/main/java/jakarta/faces/event/PhaseEvent.java +++ b/impl/src/main/java/jakarta/faces/event/PhaseEvent.java @@ -60,7 +60,7 @@ public PhaseEvent(FacesContext context, PhaseId phaseId, Lifecycle lifecycle) { // ------------------------------------------------------------- Properties - private FacesContext context = null; + private final FacesContext context; /** *

@@ -76,7 +76,7 @@ public FacesContext getFacesContext() { } - private PhaseId phaseId = null; + private final PhaseId phaseId; /** *

diff --git a/impl/src/main/java/jakarta/faces/event/ScopeContext.java b/impl/src/main/java/jakarta/faces/event/ScopeContext.java index 2a3c25e07d..7507d1aa28 100644 --- a/impl/src/main/java/jakarta/faces/event/ScopeContext.java +++ b/impl/src/main/java/jakarta/faces/event/ScopeContext.java @@ -28,8 +28,8 @@ */ public class ScopeContext { - private String scopeName; - private Map scope; + private final String scopeName; + private final Map scope; // ------------------------------------------------------------ Constructors diff --git a/impl/src/main/java/jakarta/faces/model/DataModel.java b/impl/src/main/java/jakarta/faces/model/DataModel.java index eac9f347e8..fce707358a 100644 --- a/impl/src/main/java/jakarta/faces/model/DataModel.java +++ b/impl/src/main/java/jakarta/faces/model/DataModel.java @@ -252,7 +252,7 @@ public Iterator iterator() { @SuppressWarnings({ "unchecked" }) private static final class DataModelIterator implements Iterator { - private DataModel model; + private final DataModel model; private int index; // -------------------------------------------------------- Constructors diff --git a/impl/src/main/java/jakarta/faces/model/SelectItemGroup.java b/impl/src/main/java/jakarta/faces/model/SelectItemGroup.java index 7f2d1aaf97..009f175900 100644 --- a/impl/src/main/java/jakarta/faces/model/SelectItemGroup.java +++ b/impl/src/main/java/jakarta/faces/model/SelectItemGroup.java @@ -117,7 +117,7 @@ public SelectItemGroup(String label, String description, boolean disabled, Colle // ------------------------------------------------------ Instance Variables - private SelectItem selectItems[] = null; + private SelectItem[] selectItems = null; // -------------------------------------------------------------- Properties @@ -168,7 +168,7 @@ public void setSelectItems(Collection selectItems) { if (selectItems == null) { throw new NullPointerException(); } - setSelectItems(selectItems.toArray(new SelectItem[selectItems.size()])); + setSelectItems(selectItems.toArray(new SelectItem[0])); } diff --git a/impl/src/main/java/jakarta/faces/webapp/FacesServlet.java b/impl/src/main/java/jakarta/faces/webapp/FacesServlet.java index b65f8c5e8d..628bd9da86 100644 --- a/impl/src/main/java/jakarta/faces/webapp/FacesServlet.java +++ b/impl/src/main/java/jakarta/faces/webapp/FacesServlet.java @@ -277,7 +277,7 @@ private enum HttpMethod { OPTIONS("OPTIONS"), GET("GET"), HEAD("HEAD"), POST("POST"), PUT("PUT"), DELETE("DELETE"), TRACE("TRACE"), CONNECT("CONNECT"); - private String name; + private final String name; HttpMethod(String name) { this.name = name; @@ -432,7 +432,7 @@ public void service(ServletRequest req, ServletResponse resp) throws IOException return; } - logIfThreadInterruped(); + logIfThreadInterrupted(); // If prefix mapped, then ensure requests for /WEB-INF are not processed. if (notProcessWebInfIfPrefixMapped(request, response)) { @@ -573,10 +573,8 @@ private void initHttpMethodValidityVerification() { logUnknownHttpMethod(httpMethod); - // prevent duplicates - if (!allowedUnknownHttpMethods.contains(httpMethod)) { - allowedUnknownHttpMethods.add(httpMethod); - } + // we use a Set to prevent duplicates + allowedUnknownHttpMethods.add(httpMethod); } else { // prevent duplicates if (!allowedKnownHttpMethodsStringList.contains(httpMethod)) { @@ -626,7 +624,7 @@ private void initializeAllowedKnownHttpMethods(List allowedKnownHttpMeth } } - private void logIfThreadInterruped() { + private void logIfThreadInterrupted() { if (Thread.currentThread().isInterrupted()) { if (LOGGER.isLoggable(FINER)) { LOGGER.log(FINE, "Thread {0} given to FacesServlet.service() in interrupted state", Thread.currentThread().getName()); diff --git a/impl/src/main/java/jakarta/faces/webapp/MessageFactory.java b/impl/src/main/java/jakarta/faces/webapp/MessageFactory.java index 299bd1ed15..f5a5900c14 100644 --- a/impl/src/main/java/jakarta/faces/webapp/MessageFactory.java +++ b/impl/src/main/java/jakarta/faces/webapp/MessageFactory.java @@ -319,8 +319,8 @@ private String getFormattedString(String msgtext, Object[] params) { return localizedStr; } - private Locale locale; - private Object[] parameters; + private final Locale locale; + private final Object[] parameters; private Object[] resolvedParameters; } From b06d598a48a191c8e184e9e8c27a0882166681a5 Mon Sep 17 00:00:00 2001 From: pizzi80 Date: Sun, 25 Jun 2023 19:42:55 +0200 Subject: [PATCH 2/2] + fixed toArray without size Signed-off-by: pizzi80 --- impl/src/main/java/jakarta/faces/model/SelectItemGroup.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/impl/src/main/java/jakarta/faces/model/SelectItemGroup.java b/impl/src/main/java/jakarta/faces/model/SelectItemGroup.java index 009f175900..71b3ba55ff 100644 --- a/impl/src/main/java/jakarta/faces/model/SelectItemGroup.java +++ b/impl/src/main/java/jakarta/faces/model/SelectItemGroup.java @@ -168,7 +168,7 @@ public void setSelectItems(Collection selectItems) { if (selectItems == null) { throw new NullPointerException(); } - setSelectItems(selectItems.toArray(new SelectItem[0])); + setSelectItems(selectItems.toArray(new SelectItem[selectItems.size()])); }