This is an automated email from the ASF dual-hosted git repository. tv pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/turbine-core.git
commit b2ce45d7cb1c9b26089e57ec6586405c3e56aeae Author: Thomas Vandahl <[email protected]> AuthorDate: Sun Dec 14 23:29:09 2025 +0100 Clean up --- src/java/org/apache/turbine/Turbine.java | 20 +++-- src/java/org/apache/turbine/TurbineConstants.java | 4 +- .../turbine/annotation/AnnotationProcessor.java | 62 ++++++++-------- .../apache/turbine/annotation/TurbineService.java | 4 +- .../org/apache/turbine/modules/ActionEvent.java | 7 +- src/java/org/apache/turbine/modules/Assembler.java | 2 +- .../actions/sessionvalidator/SessionValidator.java | 41 +++++------ .../modules/screens/error/InvalidState.java | 19 +++-- src/java/org/apache/turbine/om/OMTool.java | 2 +- .../apache/turbine/pipeline/TurbinePipeline.java | 2 +- .../org/apache/turbine/pipeline/package-info.java | 10 +-- .../apache/turbine/services/BaseServiceBroker.java | 27 +++---- .../turbine/services/BaseUnicastRemoteService.java | 1 + .../services/FieldAnnotatedTurbineBaseService.java | 4 +- src/java/org/apache/turbine/services/Initable.java | 10 +-- .../MethodAnnotatedTurbineBaseService.java | 8 +- .../apache/turbine/services/ServiceManager.java | 6 +- .../turbine/services/TurbineBaseService.java | 8 +- .../TurbineAssemblerBrokerService.java | 4 +- .../turbine/services/jsp/TurbineJspService.java | 15 ++-- .../localization/DateTimeFormatterInterface.java | 20 ++--- .../localization/DateTimeFormatterService.java | 10 +-- .../services/localization/LocalizationTool.java | 12 +-- .../localization/RundataLocalizationInterface.java | 4 +- .../turbine/services/pull/ApplicationTool.java | 4 +- .../services/pull/PipelineDataApplicationTool.java | 2 +- .../turbine/services/pull/TurbinePullService.java | 70 +++++++----------- .../turbine/services/pull/tools/ContentTool.java | 5 +- .../turbine/services/pull/tools/TemplateLink.java | 11 ++- .../apache/turbine/services/pull/tools/UITool.java | 13 ++-- .../services/pull/util/DateTimeFormatterTool.java | 26 +++---- .../services/rundata/DefaultTurbineRunData.java | 14 +--- .../services/rundata/TurbineRunDataService.java | 22 +++--- .../schedule/AbstractSchedulerService.java | 2 +- .../services/schedule/JobEntryNonPersistent.java | 4 +- .../turbine/services/schedule/JobEntryQuartz.java | 4 +- .../apache/turbine/services/schedule/JobQueue.java | 8 +- .../services/schedule/QuartzSchedulerService.java | 11 +-- .../services/schedule/TorqueSchedulerService.java | 4 +- .../services/security/DefaultSecurityService.java | 14 ++-- .../services/security/DefaultUserManager.java | 20 ++--- .../services/servlet/TurbineServletService.java | 3 +- .../services/template/TurbineTemplateService.java | 20 ++--- .../turbine/services/ui/TurbineUIService.java | 2 +- .../urlmapper/TurbineURLMapperService.java | 12 +-- .../services/velocity/TurbineVelocityService.java | 15 ++-- src/java/org/apache/turbine/util/FormMessages.java | 85 +++++++++------------- src/java/org/apache/turbine/util/HttpUtils.java | 12 +-- src/java/org/apache/turbine/util/ObjectUtils.java | 8 +- .../org/apache/turbine/util/SecurityCheck.java | 6 +- .../org/apache/turbine/util/TurbineConfig.java | 6 +- .../org/apache/turbine/util/TurbineXmlConfig.java | 4 +- .../apache/turbine/util/template/TemplateInfo.java | 3 +- src/java/org/apache/turbine/util/uri/URIParam.java | 8 +- .../turbine/util/velocity/VelocityEmail.java | 2 +- src/test/org/apache/turbine/ConfigurationTest.java | 10 ++- .../apache/turbine/modules/ActionLoaderTest.java | 2 +- ...VelocityActionWithExtendedServiceInjection.java | 8 +- .../apache/turbine/om/MockRetrieverFactory.java | 2 +- src/test/org/apache/turbine/om/OMToolTest.java | 4 +- .../turbine/pipeline/PipelineCreationTest.java | 53 +++++--------- .../services/ServiceWithServiceInjection.java | 26 +++---- .../services/ServiceWithServiceInjection2.java | 18 ++--- .../localization/LocalizationToolTest.java | 3 +- .../localization/RundataLocalizationToolTest.java | 14 ++-- .../urlmapper/TurbineURLMapperJSONServiceTest.java | 8 +- .../urlmapper/TurbineURLMapperServiceTest.java | 7 +- src/test/org/apache/turbine/test/BaseTestCase.java | 6 +- .../BuildContainerWithDockerfileTest.java | 15 +++- .../UserManagerWithContainerTest.java | 4 +- .../org/apache/turbine/util/ObjectUtilsTest.java | 8 +- 71 files changed, 421 insertions(+), 489 deletions(-) diff --git a/src/java/org/apache/turbine/Turbine.java b/src/java/org/apache/turbine/Turbine.java index f31c7629..6728ced3 100644 --- a/src/java/org/apache/turbine/Turbine.java +++ b/src/java/org/apache/turbine/Turbine.java @@ -561,11 +561,11 @@ public class Turbine extends HttpServlet String serviceName = i.next(); Object service = services.getService(serviceName); - if (service instanceof Initable) + if (service instanceof Initable initable) { try { - ((Initable) service).init(data); + initable.init(data); } catch (InitializationException e) { @@ -949,7 +949,8 @@ public class Turbine extends HttpServlet if (log4jFile != null) { org.apache.logging.log4j.spi.LoggerContext ctxContext = LogManager.getContext(null, false, log4jFile.toUri()); - if (ctxContext instanceof LoggerContext) { + if (ctxContext instanceof LoggerContext) + { log.info("resolved log4j2 location: {}", context.getConfiguration().getConfigurationSource().getLocation()); } @@ -990,16 +991,13 @@ public class Turbine extends HttpServlet { log4jTarget = logFilePath.normalize(); } - else + else // fall back just using the filename, if path match + if (log4jFilePath != null && log4jFilePath.getParent() != null && logConfPath.endsWith(log4jFilePath.getParent())) { - // fall back just using the filename, if path match - if (log4jFilePath != null && log4jFilePath.getParent() != null && logConfPath.endsWith(log4jFilePath.getParent())) + logFilePath = logConfPath.resolve(log4jFilePath.getFileName()); + if (logFilePath != null && logFilePath.toFile().exists()) { - logFilePath = logConfPath.resolve(log4jFilePath.getFileName()); - if (logFilePath != null && logFilePath.toFile().exists()) - { - log4jTarget = logFilePath.normalize(); - } + log4jTarget = logFilePath.normalize(); } } } diff --git a/src/java/org/apache/turbine/TurbineConstants.java b/src/java/org/apache/turbine/TurbineConstants.java index 9555c569..6db6be18 100644 --- a/src/java/org/apache/turbine/TurbineConstants.java +++ b/src/java/org/apache/turbine/TurbineConstants.java @@ -184,8 +184,8 @@ public interface TurbineConstants /** Session Timeout Default Value */ int SESSION_TIMEOUT_DEFAULT = -1; - /** - * Filter for classes that can be de-serialized from the persistent session storage + /** + * Filter for classes that can be de-serialized from the persistent session storage * See {@link java.io.ObjectInputFilter.Config#createFilter(String)} */ String SESSION_OBJECTINPUTFILTER = "session.objectinputfilter"; diff --git a/src/java/org/apache/turbine/annotation/AnnotationProcessor.java b/src/java/org/apache/turbine/annotation/AnnotationProcessor.java index 1936fc04..8df25098 100644 --- a/src/java/org/apache/turbine/annotation/AnnotationProcessor.java +++ b/src/java/org/apache/turbine/annotation/AnnotationProcessor.java @@ -120,9 +120,8 @@ public class AnnotationProcessor for (Annotation annotation : annotations) { - if (annotation instanceof TurbineRequiredRole) + if (annotation instanceof TurbineRequiredRole trr) { - TurbineRequiredRole trr = (TurbineRequiredRole) annotation; String[] roleNames = trr.value(); String group = trr.group(); @@ -170,9 +169,8 @@ public class AnnotationProcessor } } } - else if (annotation instanceof TurbineRequiredPermission) + else if (annotation instanceof TurbineRequiredPermission trp) { - TurbineRequiredPermission trp = (TurbineRequiredPermission) annotation; String[] permissionNames = trp.value(); String group = trp.group(); @@ -250,13 +248,13 @@ public class AnnotationProcessor AssemblerBrokerService assembler = null; PoolService pool= null; Class<?> clazz = object.getClass(); - + boolean isTurbineService = false; if ( clazz.isAnnotationPresent(TurbineService.class)) { TurbineService service = clazz.getAnnotation(TurbineService.class); log.debug("retrieved class annotation: "+ service); isTurbineService = true; - } + } while (clazz != null) { @@ -268,39 +266,39 @@ public class AnnotationProcessor for (Annotation a : annotations) { - if (a instanceof TurbineService) + if (a instanceof TurbineService ts) { if (manager == null) { manager = TurbineServices.getInstance(); } - injectTurbineService(object, manager, field, (TurbineService) a); + injectTurbineService(object, manager, field, ts); } - else if (a instanceof TurbineConfiguration) + else if (a instanceof TurbineConfiguration tc) { if (config == null) { config = Turbine.getConfiguration(); } - injectTurbineConfiguration(object, config, field, (TurbineConfiguration) a); + injectTurbineConfiguration(object, config, field, tc); } - else if (a instanceof TurbineLoader) + else if (a instanceof TurbineLoader tl) { if (assembler == null) { assembler = (AssemblerBrokerService) TurbineServices.getInstance(). getService(AssemblerBrokerService.SERVICE_NAME); } - injectTurbineLoader(object, assembler, field, (TurbineLoader) a); + injectTurbineLoader(object, assembler, field, tl); } - else if (a instanceof TurbineTool) + else if (a instanceof TurbineTool tt) { if (pool == null) { pool = (PoolService)TurbineServices.getInstance() .getService(PoolService.ROLE); } - injectTurbineTool(object, pool, field, (TurbineTool) a); + injectTurbineTool(object, pool, field, tt); } } if (isTurbineService) @@ -313,7 +311,7 @@ public class AnnotationProcessor manager = TurbineServices.getInstance(); } injectTurbineService(object, manager, field, service); - } + } } } @@ -333,14 +331,14 @@ public class AnnotationProcessor Annotation[] annotations = getAnnotations(method); for (Annotation a : annotations) { - if (a instanceof TurbineService) + if (a instanceof TurbineService ts) { if (manager == null) { manager = TurbineServices.getInstance(); } - injectTurbineService(object, manager, method, (TurbineService) a); + injectTurbineService(object, manager, method, ts); } } if (isTurbineService) @@ -356,8 +354,8 @@ public class AnnotationProcessor TurbineService service = c.getAnnotation(TurbineService.class); log.debug("retrieved implicit service in Turbien service: "+ service); injectTurbineService(object, manager, method, service); - } - + } + } } } @@ -391,9 +389,9 @@ public class AnnotationProcessor + loader + " into object " + object, e); } } - + /** - * Inject Turbine tool into field of object and + * Inject Turbine tool into field of object and * injects annotations provided in the tool. * * @param object the object to process @@ -421,7 +419,7 @@ public class AnnotationProcessor { throw new TurbineException("Could not inject tool " + tool + " into object " + object, e); - } + } } /** @@ -542,14 +540,14 @@ public class AnnotationProcessor field.setAccessible(true); field.set(object, values); } else { - throw new TurbineException("Could not inject type " + + throw new TurbineException("Could not inject type " + type + " into object " + object + ". Type "+ type + " not assignable in configuration " + conf + " (allowed: String, Boolean, List, Number Types, "+ Configuration.class.getName() + ")."); } } else { field.setAccessible(true); Object defaultValue = field.get(object); - // this should not throw an error as it might be set later from container e. g. session.timeout + // this should not throw an error as it might be set later from container e. g. session.timeout // we might check field.get<Type> to show the default value of the field, but this is only a guess, it might be set even later.. log.info("No key {} of type {} injected into object {}. Field {} is set to default {}.", key, type, object, field.getName(), defaultValue); } @@ -581,7 +579,7 @@ public class AnnotationProcessor } // Check for fields SERVICE_NAME and ROLE else - { + { // check field level annotation Field[] typeFields = field.getType().getFields(); serviceName = checkServiceOrRoleInField(serviceName, typeFields); @@ -591,7 +589,7 @@ public class AnnotationProcessor TurbineService service = field.getType().getAnnotation(TurbineService.class); log.debug("retrieved class annotation: "+ service); serviceName = service.value(); - } + } } if (StringUtils.isEmpty(serviceName)) @@ -619,8 +617,8 @@ public class AnnotationProcessor } /** - * Injects Turbine service into method fields - * + * Injects Turbine service into method fields + * * @param object the object to process * @param manager the service manager * @param method The method @@ -643,14 +641,14 @@ public class AnnotationProcessor Field[] fields = c.getFields(); // Check for fields SERVICE_NAME and ROLE serviceName = checkServiceOrRoleInField(serviceName, fields); - + if ( (serviceName == null || serviceName.equals(Service.SERVICE_NAME)) && c.isAnnotationPresent(TurbineService.class)) { TurbineService service = c.getAnnotation(TurbineService.class); log.debug("retrieved class annotation: "+ service); serviceName = service.value(); - } - + } + } } @@ -681,6 +679,7 @@ public class AnnotationProcessor private static String checkServiceOrRoleInField(String serviceName, Field[] fields) { for (Field f : fields) + { if (TurbineService.SERVICE_NAME.equals(f.getName())) { try @@ -705,6 +704,7 @@ public class AnnotationProcessor } break; } + } return serviceName; } } diff --git a/src/java/org/apache/turbine/annotation/TurbineService.java b/src/java/org/apache/turbine/annotation/TurbineService.java index e9d653d2..4379015d 100644 --- a/src/java/org/apache/turbine/annotation/TurbineService.java +++ b/src/java/org/apache/turbine/annotation/TurbineService.java @@ -27,8 +27,8 @@ import java.lang.annotation.Target; /** * Annotation to mark class and fields in modules that require a service to be injected - * - * Explicit field annotation of {@link #SERVICE_NAME} will take precedence of class annotation. + * + * Explicit field annotation of {@link #SERVICE_NAME} will take precedence of class annotation. */ @Retention( RetentionPolicy.RUNTIME ) @Target( {ElementType.TYPE, ElementType.FIELD, ElementType.METHOD} ) diff --git a/src/java/org/apache/turbine/modules/ActionEvent.java b/src/java/org/apache/turbine/modules/ActionEvent.java index 0b0ad64a..18c63e67 100644 --- a/src/java/org/apache/turbine/modules/ActionEvent.java +++ b/src/java/org/apache/turbine/modules/ActionEvent.java @@ -152,9 +152,8 @@ public abstract class ActionEvent implements Action Annotation[] annotations = AnnotationProcessor.getAnnotations(m); for (Annotation a : annotations) { - if (a instanceof TurbineActionEvent) + if (a instanceof TurbineActionEvent tae) { - TurbineActionEvent tae = (TurbineActionEvent) a; if (name.equals(pp.convert(tae.value())) && Arrays.equals(signature, m.getParameterTypes())) { @@ -266,9 +265,9 @@ public abstract class ActionEvent implements Action Throwable t = ite.getTargetException(); if (bubbleUpException) { - if (t instanceof Exception) + if (t instanceof Exception e) { - throw (Exception) t; + throw e; } else { diff --git a/src/java/org/apache/turbine/modules/Assembler.java b/src/java/org/apache/turbine/modules/Assembler.java index 7d6a4771..5d4012ab 100644 --- a/src/java/org/apache/turbine/modules/Assembler.java +++ b/src/java/org/apache/turbine/modules/Assembler.java @@ -23,7 +23,7 @@ package org.apache.turbine.modules; * This is an interface that defines what an Assembler is. All the current * modules extend off of this class. It is currently empty and future use is yet * to be determined. - * + * * Currently this are mostly one of the classes, which could be loaded by {@link Loader}. * Check also the assembler classes having a loader {@link GenericLoader}. * diff --git a/src/java/org/apache/turbine/modules/actions/sessionvalidator/SessionValidator.java b/src/java/org/apache/turbine/modules/actions/sessionvalidator/SessionValidator.java index fb48671c..a7da6e8b 100644 --- a/src/java/org/apache/turbine/modules/actions/sessionvalidator/SessionValidator.java +++ b/src/java/org/apache/turbine/modules/actions/sessionvalidator/SessionValidator.java @@ -91,30 +91,29 @@ public abstract class SessionValidator implements Action data.setScreen(screenInvalidState); data.setAction(""); } - } else { - if (!security.isAnonymousUser(data.getUser())) + } + else if (!security.isAnonymousUser(data.getUser())) + { + // See comments in screens.error.InvalidState. + if (data.getParameters().getInt("_session_access_counter") + < (((Integer) data.getUser().getTemp( + "_session_access_counter")).intValue() - 1)) { - // See comments in screens.error.InvalidState. - if (data.getParameters().getInt("_session_access_counter") - < (((Integer) data.getUser().getTemp( - "_session_access_counter")).intValue() - 1)) + if (data.getTemplateInfo().getScreenTemplate() != null) { - if (data.getTemplateInfo().getScreenTemplate() != null) - { - data.getUser().setTemp("prev_template", - data.getTemplateInfo().getScreenTemplate() - .replace('/', ',')); - data.getTemplateInfo().setScreenTemplate(templateInvalidState); - } - else - { - data.getUser().setTemp("prev_screen", - data.getScreen().replace('/', ',')); - data.setScreen(screenInvalidState); - } - data.getUser().setTemp("prev_parameters", data.getParameters()); - data.setAction(""); + data.getUser().setTemp("prev_template", + data.getTemplateInfo().getScreenTemplate() + .replace('/', ',')); + data.getTemplateInfo().setScreenTemplate(templateInvalidState); } + else + { + data.getUser().setTemp("prev_screen", + data.getScreen().replace('/', ',')); + data.setScreen(screenInvalidState); + } + data.getUser().setTemp("prev_parameters", data.getParameters()); + data.setAction(""); } } } diff --git a/src/java/org/apache/turbine/modules/screens/error/InvalidState.java b/src/java/org/apache/turbine/modules/screens/error/InvalidState.java index bf9795b1..84902356 100644 --- a/src/java/org/apache/turbine/modules/screens/error/InvalidState.java +++ b/src/java/org/apache/turbine/modules/screens/error/InvalidState.java @@ -60,16 +60,15 @@ public class InvalidState implements Screen body.append("<body>"); StringBuilder message = new StringBuilder(); - StringBuilder sb = new StringBuilder(); - sb.append("<b>There has been an error.</b>") - .append("<p>") - .append("- If you used the browser \"Back\" or \"Reload\"") - .append(" buttons please use the navigation buttons we provide") - .append(" within the screen.") - .append("<p>") - .append("Please click "); - - message.append(sb.toString()); + String str = """ + <b>There has been an error.</b>\ + <p>\ + - If you used the browser "Back" or "Reload"\ + buttons please use the navigation buttons we provide\ + within the screen.\ + <p>\ + Please click """; + message.append(str); ParameterParser pp; pp = (ParameterParser) data.getUser().getTemp("prev_parameters"); pp.remove("_session_access_counter"); diff --git a/src/java/org/apache/turbine/om/OMTool.java b/src/java/org/apache/turbine/om/OMTool.java index 93e27422..a499ae8d 100644 --- a/src/java/org/apache/turbine/om/OMTool.java +++ b/src/java/org/apache/turbine/om/OMTool.java @@ -46,7 +46,7 @@ public class OMTool implements ApplicationTool, Recyclable // though /** The cache of PullHelpers. **/ - private ConcurrentMap<String, OMTool.PullHelper> pullMap = + private final ConcurrentMap<String, OMTool.PullHelper> pullMap = new ConcurrentHashMap<>(); /** diff --git a/src/java/org/apache/turbine/pipeline/TurbinePipeline.java b/src/java/org/apache/turbine/pipeline/TurbinePipeline.java index fc9d3e4b..1d86dba4 100644 --- a/src/java/org/apache/turbine/pipeline/TurbinePipeline.java +++ b/src/java/org/apache/turbine/pipeline/TurbinePipeline.java @@ -68,7 +68,7 @@ public class TurbinePipeline /** * The per-thread execution state for processing through this pipeline. */ - private ThreadLocal<Iterator<Valve>> state = new ThreadLocal<>(); + private final ThreadLocal<Iterator<Valve>> state = new ThreadLocal<>(); /** * @see org.apache.turbine.pipeline.Pipeline#initialize() diff --git a/src/java/org/apache/turbine/pipeline/package-info.java b/src/java/org/apache/turbine/pipeline/package-info.java index 682fbcdd..b20d6916 100644 --- a/src/java/org/apache/turbine/pipeline/package-info.java +++ b/src/java/org/apache/turbine/pipeline/package-info.java @@ -18,7 +18,7 @@ */ /** - * + * * <p> * The Turbine processing pipeline is modeled after the pipeline found * in Tomcat 4.0.1 (Catalina), and after the module architecture found @@ -28,11 +28,11 @@ * Pipeline (ClassicPipeline) can be changed by replacing or extending * the implementation with a custom one. * </p> - * + * * <p> * As with Catalina, Turbine's Pipeline and Valve configuration is * setup via XML: - * + * * <code> * <pipeline name="default"> * <valves> @@ -49,11 +49,11 @@ * </pipeline> * </code> * </p> - * + * * <p> * Please direct all comments, fixes, and enhancements to the * <a href="mailto:[email protected]">development list</a>. * </p> - * + * */ package org.apache.turbine.pipeline; diff --git a/src/java/org/apache/turbine/services/BaseServiceBroker.java b/src/java/org/apache/turbine/services/BaseServiceBroker.java index d4afc6a3..9f2f48ac 100644 --- a/src/java/org/apache/turbine/services/BaseServiceBroker.java +++ b/src/java/org/apache/turbine/services/BaseServiceBroker.java @@ -356,15 +356,15 @@ public abstract class BaseServiceBroker implements ServiceBroker Service instance = getServiceInstance(name); serviceLock.lock(); - try + try { if (!instance.getInit()) { // this call might result in an indirect recursion instance.init(); } - } - finally + } + finally { serviceLock.unlock(); } @@ -462,16 +462,19 @@ public abstract class BaseServiceBroker implements ServiceBroker if (service != null && service.getInit()) { serviceLock.lock(); - try { + try + { service.shutdown(); - if (service.getInit() && service instanceof BaseService) + if (service.getInit() && service instanceof BaseService base) { // BaseService::shutdown() does this by default, // but could've been overriden poorly. - ((BaseService) service).setInit(false); + base.setInit(false); } - } finally { + } + finally + { serviceLock.unlock(); } } @@ -539,7 +542,7 @@ public abstract class BaseServiceBroker implements ServiceBroker if (!service.getInit()) { serviceLock.lock(); // was synchronized (service.getClass(), but should be equivalent - try + try { if (!service.getInit()) { @@ -547,8 +550,8 @@ public abstract class BaseServiceBroker implements ServiceBroker service.init(); log.info("Finish Initializing service (late): {}", name); } - } - finally + } + finally { serviceLock.unlock(); } @@ -605,7 +608,7 @@ public abstract class BaseServiceBroker implements ServiceBroker protected Service getServiceInstance(String serviceName) throws InstantiationException { - Service service = services.computeIfAbsent(serviceName, name -> + return services.computeIfAbsent(serviceName, name -> { serviceLock.lock(); try @@ -667,8 +670,6 @@ public abstract class BaseServiceBroker implements ServiceBroker serviceLock.unlock(); } }); - - return service; } /** diff --git a/src/java/org/apache/turbine/services/BaseUnicastRemoteService.java b/src/java/org/apache/turbine/services/BaseUnicastRemoteService.java index e310837b..b6e59191 100644 --- a/src/java/org/apache/turbine/services/BaseUnicastRemoteService.java +++ b/src/java/org/apache/turbine/services/BaseUnicastRemoteService.java @@ -92,6 +92,7 @@ public class BaseUnicastRemoteService extends UnicastRemoteObject setInit(true); } + @Override public void setInit(boolean value) { isInitialized = value; diff --git a/src/java/org/apache/turbine/services/FieldAnnotatedTurbineBaseService.java b/src/java/org/apache/turbine/services/FieldAnnotatedTurbineBaseService.java index b8037a44..1182a1ec 100644 --- a/src/java/org/apache/turbine/services/FieldAnnotatedTurbineBaseService.java +++ b/src/java/org/apache/turbine/services/FieldAnnotatedTurbineBaseService.java @@ -27,7 +27,7 @@ import org.apache.turbine.util.TurbineException; /** * <p>This class provides a <code>Service</code> implementation that - * Services used in Turbine are required to extend. + * Services used in Turbine are required to extend. * This class provides the ability to process field annotation {@link TurbineServices} in a Turbine service. * You could enable scanning globally by annotating the class (service) with the annotation {@link TurbineServices}. * Field annotation could then be omitted, if the field class is {@link TurbineServices} annotated. @@ -37,7 +37,7 @@ import org.apache.turbine.util.TurbineException; public abstract class FieldAnnotatedTurbineBaseService extends TurbineBaseService { - + private static Logger log = LogManager.getLogger(FieldAnnotatedTurbineBaseService.class); /** * Performs late initialization. diff --git a/src/java/org/apache/turbine/services/Initable.java b/src/java/org/apache/turbine/services/Initable.java index d30f1600..36e315d4 100644 --- a/src/java/org/apache/turbine/services/Initable.java +++ b/src/java/org/apache/turbine/services/Initable.java @@ -47,7 +47,7 @@ public interface Initable * throw an exception and complain. * * Default: do nothing - * + * * @param data An Object to use for initialization activities. * @throws InitializationException if initialization of this * class was not successful. @@ -56,13 +56,13 @@ public interface Initable /** * Performs late initialization of an Initable. - * + * * When your class is being requested from an InitableBroker, it * will call getInit(), and if it returns false, this method will * be invoked. * * Default: do nothing - * + * * @throws InitializationException if initialization of this * class was not successful. */ @@ -76,7 +76,7 @@ public interface Initable * You may chose to implement this operation or not. If you support * this operation, getInit() should return false after successful * shutdown of the service. - * + * * Default: setInit(false) */ default void shutdown() { @@ -92,7 +92,7 @@ public interface Initable /** * Sets initialization status. - * + * * @param value The new initialization status. */ void setInit(boolean value); diff --git a/src/java/org/apache/turbine/services/MethodAnnotatedTurbineBaseService.java b/src/java/org/apache/turbine/services/MethodAnnotatedTurbineBaseService.java index 97c0aba8..aaa0d825 100644 --- a/src/java/org/apache/turbine/services/MethodAnnotatedTurbineBaseService.java +++ b/src/java/org/apache/turbine/services/MethodAnnotatedTurbineBaseService.java @@ -24,17 +24,17 @@ import org.apache.turbine.util.TurbineException; /** * <p>This class provides a <code>Service</code> implementation that - * Services used in Turbine are required to extend. + * Services used in Turbine are required to extend. * This class provides the ability to process field and method annotations {@link TurbineServices} in a Turbine service. - * You could also enable scanning globally by annotating the class (service) with the annotation {@link TurbineServices}, - * then method annotation could be omitted, if the argument class is {@link TurbineServices} annotated. + * You could also enable scanning globally by annotating the class (service) with the annotation {@link TurbineServices}, + * then method annotation could be omitted, if the argument class is {@link TurbineServices} annotated. * </p> * */ public abstract class MethodAnnotatedTurbineBaseService extends TurbineBaseService { - + /** * Performs late initialization. * diff --git a/src/java/org/apache/turbine/services/ServiceManager.java b/src/java/org/apache/turbine/services/ServiceManager.java index 9d5a736e..50e961b9 100644 --- a/src/java/org/apache/turbine/services/ServiceManager.java +++ b/src/java/org/apache/turbine/services/ServiceManager.java @@ -67,7 +67,7 @@ public interface ServiceManager extends ServiceBroker * @param applicationRoot application root */ void setApplicationRoot(String applicationRoot); - + /** * Set an application specific service object * that can be used by application specific @@ -76,7 +76,7 @@ public interface ServiceManager extends ServiceBroker * @param name name of service object * @param value value of service object */ - public void setServiceObject(String name, Object value); + void setServiceObject(String name, Object value); /** * Get an application specific service object. @@ -84,5 +84,5 @@ public interface ServiceManager extends ServiceBroker * @param name the name of the service object * @return Object application specific service object */ - public Object getServiceObject(String name); + Object getServiceObject(String name); } diff --git a/src/java/org/apache/turbine/services/TurbineBaseService.java b/src/java/org/apache/turbine/services/TurbineBaseService.java index 9f008638..27d312ab 100644 --- a/src/java/org/apache/turbine/services/TurbineBaseService.java +++ b/src/java/org/apache/turbine/services/TurbineBaseService.java @@ -72,13 +72,13 @@ public abstract class TurbineBaseService public void init(Object data) throws InitializationException { - if (data instanceof RunData) + if (data instanceof RunData rd) { - init((RunData) data); + init(rd); } - else if (data instanceof PipelineData) + else if (data instanceof PipelineData pd) { - init((PipelineData) data); + init(pd); } } diff --git a/src/java/org/apache/turbine/services/assemblerbroker/TurbineAssemblerBrokerService.java b/src/java/org/apache/turbine/services/assemblerbroker/TurbineAssemblerBrokerService.java index 4ac606da..79900762 100644 --- a/src/java/org/apache/turbine/services/assemblerbroker/TurbineAssemblerBrokerService.java +++ b/src/java/org/apache/turbine/services/assemblerbroker/TurbineAssemblerBrokerService.java @@ -22,10 +22,8 @@ package org.apache.turbine.services.assemblerbroker; import java.util.ArrayList; -import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -85,7 +83,7 @@ public class TurbineAssemblerBrokerService @SuppressWarnings("unchecked") private <T extends Assembler> List<AssemblerFactory<T>> getFactoryGroup(Class<T> type) { - return (List<AssemblerFactory<T>>) factories.computeIfAbsent(type, + return (List<AssemblerFactory<T>>) factories.computeIfAbsent(type, k -> new ArrayList<AssemblerFactory<T>>()); } diff --git a/src/java/org/apache/turbine/services/jsp/TurbineJspService.java b/src/java/org/apache/turbine/services/jsp/TurbineJspService.java index 0d84da28..54406930 100644 --- a/src/java/org/apache/turbine/services/jsp/TurbineJspService.java +++ b/src/java/org/apache/turbine/services/jsp/TurbineJspService.java @@ -25,9 +25,6 @@ import java.io.File; import java.io.IOException; import java.util.Arrays; -import jakarta.servlet.RequestDispatcher; -import jakarta.servlet.http.HttpServletRequest; - import org.apache.commons.configuration2.Configuration; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; @@ -38,9 +35,11 @@ import org.apache.turbine.services.InitializationException; import org.apache.turbine.services.pull.ApplicationTool; import org.apache.turbine.services.pull.tools.TemplateLink; import org.apache.turbine.services.template.BaseTemplateEngineService; -import org.apache.turbine.util.RunData; import org.apache.turbine.util.TurbineException; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.http.HttpServletRequest; + /** * This is a Service that can process JSP templates from within a Turbine * screen. @@ -138,12 +137,8 @@ public class TurbineJspService public void handleRequest(PipelineData pipelineData, String templateName, boolean isForward) throws TurbineException { - if(!(pipelineData instanceof RunData)) - { - throw new RuntimeException("Can't cast to rundata from pipeline data."); - } - - RunData data = (RunData)pipelineData; + // throws TurbineRuntimeException if cast fails + pipelineData.getRunData(); /** template name with relative path */ String relativeTemplateName = getRelativeTemplateName(templateName); diff --git a/src/java/org/apache/turbine/services/localization/DateTimeFormatterInterface.java b/src/java/org/apache/turbine/services/localization/DateTimeFormatterInterface.java index 20c1be52..e4ddc6ba 100644 --- a/src/java/org/apache/turbine/services/localization/DateTimeFormatterInterface.java +++ b/src/java/org/apache/turbine/services/localization/DateTimeFormatterInterface.java @@ -30,16 +30,16 @@ public interface DateTimeFormatterInterface { * Property tag for the date format that is to be used for the web * application. "tool.dateTool.format" */ - final String DATE_TIME_FORMAT_KEY = "datetime.format"; - - final String DATE_TIME_ZONEID_KEY = "datetime.zoneId"; - - final String USE_TURBINE_LOCALE_KEY = "datetime.use.turbine.locale"; - - final String USE_REQUEST_LOCALE_KEY = "tool.use.request.locale"; - + String DATE_TIME_FORMAT_KEY = "datetime.format"; + + String DATE_TIME_ZONEID_KEY = "datetime.zoneId"; + + String USE_TURBINE_LOCALE_KEY = "datetime.use.turbine.locale"; + + String USE_REQUEST_LOCALE_KEY = "tool.use.request.locale"; + /** Default date format. find supported formats in {@link DateTimeFormatterService} */ - final String DATE_TIME_FORMAT_DEFAULT = "MM/dd/yyyy"; + String DATE_TIME_FORMAT_DEFAULT = "MM/dd/yyyy"; DateTimeFormatter getDefaultFormat(); @@ -74,7 +74,7 @@ public interface DateTimeFormatterInterface { * @return String value of the date */ <T extends TemporalAccessor> String format(T temporalAccessor, String dateFormatString, Locale locale); - + /** * Formats the given date as a String. * diff --git a/src/java/org/apache/turbine/services/localization/DateTimeFormatterService.java b/src/java/org/apache/turbine/services/localization/DateTimeFormatterService.java index 582cfb66..17cf6d6f 100644 --- a/src/java/org/apache/turbine/services/localization/DateTimeFormatterService.java +++ b/src/java/org/apache/turbine/services/localization/DateTimeFormatterService.java @@ -38,7 +38,7 @@ import org.apache.turbine.util.LocaleUtils; * This service is used to format {@link TemporalAccessor} and * {@link #map(String, DateTimeFormatter, Locale)} (different flavors) * objects into strings. - * <p> + * <p> * The methods may throw {@link java.time.temporal.UnsupportedTemporalTypeException} or * {@link DateTimeParseException}, e.g. * if the source and the target format do not match appropriately. @@ -47,7 +47,7 @@ import org.apache.turbine.util.LocaleUtils; */ @TurbineService("DateTimeFormatterService") public class DateTimeFormatterService - extends TurbineBaseService implements DateTimeFormatterInterface + extends TurbineBaseService implements DateTimeFormatterInterface { private String formatPattern = null; @@ -75,12 +75,12 @@ public class DateTimeFormatterService * Initialize the service. * <p> <p> <p> <p> * the {@link #dateTimeFormat} from {@link #formatPattern} is initialized with - * + * * <ol> * <li>{@link Locale}: {@link LocaleUtils#getDefaultLocale()} is used by default. * It could be overridden setting #USE_TURBINE_LOCALE_KEY to false, the * the default Locale {@link Locale#getDefault()} is used. - * </li><li>{@link ZoneId}: If #DATE_TIME_ZONEID_KEY is set this {@link ZoneId} + * </li><li>{@link ZoneId}: If #DATE_TIME_ZONEID_KEY is set this {@link ZoneId} * is used else {@link ZoneId#systemDefault()}. * </li> * </ol> @@ -245,7 +245,7 @@ public class DateTimeFormatterService public void setLocale(Locale locale) { this.locale = locale; } - + @Override public ZoneId getZoneId() { return zoneId; diff --git a/src/java/org/apache/turbine/services/localization/LocalizationTool.java b/src/java/org/apache/turbine/services/localization/LocalizationTool.java index 6e0955a8..2682b0b2 100644 --- a/src/java/org/apache/turbine/services/localization/LocalizationTool.java +++ b/src/java/org/apache/turbine/services/localization/LocalizationTool.java @@ -22,9 +22,9 @@ package org.apache.turbine.services.localization; import java.util.Locale; import java.util.MissingResourceException; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; import org.apache.fulcrum.localization.LocalizationService; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.turbine.annotation.TurbineService; import org.apache.turbine.services.pull.ApplicationTool; import org.apache.turbine.util.RunData; @@ -133,13 +133,13 @@ public class LocalizationTool implements ApplicationTool @Override public void init(Object data) { - if (data instanceof RunData) + if (data instanceof RunData rd) { // Pull necessary information out of RunData while we have // a reference to it. - locale = (localizationService instanceof RundataLocalizationService)? - ((RundataLocalizationService)localizationService).getLocale((RunData) data): - localizationService.getLocale(((RunData) data).getRequest()); + locale = (localizationService instanceof RundataLocalizationService r) ? + r.getLocale(rd): + localizationService.getLocale(rd.getRequest()); } } diff --git a/src/java/org/apache/turbine/services/localization/RundataLocalizationInterface.java b/src/java/org/apache/turbine/services/localization/RundataLocalizationInterface.java index ab1bb87a..98c7289a 100644 --- a/src/java/org/apache/turbine/services/localization/RundataLocalizationInterface.java +++ b/src/java/org/apache/turbine/services/localization/RundataLocalizationInterface.java @@ -29,10 +29,10 @@ public interface RundataLocalizationInterface extends LocalizationService, Seria { /** * Get the locale from the session first, then fallback to normal request headers. - * + * * @param data the {@link RunData}, which allows a guess for the locale. * @return Current locale based on state. */ Locale getLocale(RunData data); - + } diff --git a/src/java/org/apache/turbine/services/pull/ApplicationTool.java b/src/java/org/apache/turbine/services/pull/ApplicationTool.java index dbb88196..03a82085 100644 --- a/src/java/org/apache/turbine/services/pull/ApplicationTool.java +++ b/src/java/org/apache/turbine/services/pull/ApplicationTool.java @@ -45,7 +45,7 @@ public interface ApplicationTool * If your session tool depends on having a <code>User</code> object, you * should look at implementing the {@link PipelineDataApplicationTool} interface * instead. - * + * * Default: do nothing * * @param data initialization data @@ -58,7 +58,7 @@ public interface ApplicationTool * probably want the tool to refresh itself * if it is using configuration information * that is typically cached after initialization - * + * * Default: do nothing */ default void refresh() {} diff --git a/src/java/org/apache/turbine/services/pull/PipelineDataApplicationTool.java b/src/java/org/apache/turbine/services/pull/PipelineDataApplicationTool.java index f7141ed0..db1364db 100644 --- a/src/java/org/apache/turbine/services/pull/PipelineDataApplicationTool.java +++ b/src/java/org/apache/turbine/services/pull/PipelineDataApplicationTool.java @@ -61,7 +61,7 @@ public interface PipelineDataApplicationTool * probably want the tool to refresh itself * if it is using configuration information * that is typically cached after initialization - * + * * Default: do nothing * * @param data The current PipelineData Object diff --git a/src/java/org/apache/turbine/services/pull/TurbinePullService.java b/src/java/org/apache/turbine/services/pull/TurbinePullService.java index 4ab67a7b..30a9d000 100644 --- a/src/java/org/apache/turbine/services/pull/TurbinePullService.java +++ b/src/java/org/apache/turbine/services/pull/TurbinePullService.java @@ -767,37 +767,32 @@ public class TurbinePullService { AnnotationProcessor.process(tool); - if (param instanceof PipelineData) + if (param instanceof PipelineData pd) { - if (tool instanceof PipelineDataApplicationTool) + if (tool instanceof PipelineDataApplicationTool pdat) { - ((PipelineDataApplicationTool) tool).init(param); + pdat.init(pd); } - else if (tool instanceof RunDataApplicationTool) + else if (tool instanceof RunDataApplicationTool rdat) { - RunData data = getRunData((PipelineData)param); - ((RunDataApplicationTool) tool).init(data); + rdat.init(pd.getRunData()); } - else if (tool instanceof ApplicationTool) + else if (tool instanceof ApplicationTool at) { - RunData data = getRunData((PipelineData)param); - ((ApplicationTool) tool).init(data); + at.init(pd.getRunData()); } } - else + else if (tool instanceof PipelineDataApplicationTool pdat) { - if (tool instanceof PipelineDataApplicationTool) - { - ((PipelineDataApplicationTool) tool).init(param); - } - else if (tool instanceof RunDataApplicationTool) - { - ((RunDataApplicationTool) tool).init(param); - } - else if (tool instanceof ApplicationTool) - { - ((ApplicationTool) tool).init(param); - } + pdat.init(param); + } + else if (tool instanceof RunDataApplicationTool rdat) + { + rdat.init(param); + } + else if (tool instanceof ApplicationTool at) + { + at.init(param); } } @@ -809,33 +804,20 @@ public class TurbinePullService */ private void refreshTool(Object tool, Object dataObject) { - RunData data = null; - PipelineData pipelineData = null; - if (dataObject instanceof PipelineData) + if (dataObject instanceof PipelineData pipelineData) { - pipelineData = (PipelineData)dataObject; - data = pipelineData.getRunData(); - if (tool instanceof PipelineDataApplicationTool) + if (tool instanceof PipelineDataApplicationTool pdat) { - ((PipelineDataApplicationTool) tool).refresh(pipelineData); + pdat.refresh(pipelineData); + } + else if (tool instanceof RunDataApplicationTool rdat) + { + rdat.refresh(pipelineData.getRunData()); } } - if (tool instanceof ApplicationTool) - { - ((ApplicationTool) tool).refresh(); - } - else if (tool instanceof RunDataApplicationTool) - { - ((RunDataApplicationTool) tool).refresh(data); - } - } - - private RunData getRunData(PipelineData pipelineData) - { - if (!(pipelineData instanceof RunData)) + if (tool instanceof ApplicationTool at) { - throw new RuntimeException("Can't cast to rundata from pipeline data."); + at.refresh(); } - return (RunData)pipelineData; } } diff --git a/src/java/org/apache/turbine/services/pull/tools/ContentTool.java b/src/java/org/apache/turbine/services/pull/tools/ContentTool.java index 017d1f62..a337738a 100644 --- a/src/java/org/apache/turbine/services/pull/tools/ContentTool.java +++ b/src/java/org/apache/turbine/services/pull/tools/ContentTool.java @@ -109,10 +109,9 @@ public class ContentTool // we just blithely cast to RunData as if another object // or null is passed in we'll throw an appropriate runtime // exception. - if (data instanceof PipelineData) + if (data instanceof PipelineData pipelineData) { - PipelineData pipelineData = (PipelineData) data; - RunData runData = (RunData)pipelineData; + RunData runData = pipelineData.getRunData(); dataURI = new DataURI(runData); } else diff --git a/src/java/org/apache/turbine/services/pull/tools/TemplateLink.java b/src/java/org/apache/turbine/services/pull/tools/TemplateLink.java index fecbcab7..d7d96d4f 100644 --- a/src/java/org/apache/turbine/services/pull/tools/TemplateLink.java +++ b/src/java/org/apache/turbine/services/pull/tools/TemplateLink.java @@ -70,7 +70,7 @@ public class TemplateLink /** Do we want a relative link? */ protected boolean wantRelative = false; - + /** * Should this tool add Container Encoding to the URIs returned? * True might cause trouble e.g. if you run with Apache HTTP Daemon / Tomcat Combo. @@ -81,7 +81,7 @@ public class TemplateLink /** Default Value for TEMPLATE_LINK_ENCODING_DEFAULT */ public static final boolean TEMPLATE_LINK_ENCODING_DEFAULT = false; - + /** Do we want the container to encode the response? */ boolean wantEncoding = false; @@ -126,10 +126,9 @@ public class TemplateLink // we just blithely cast to RunData as if another object // or null is passed in we'll throw an appropriate runtime // exception. - if (data instanceof PipelineData) + if (data instanceof PipelineData pipelineData) { - PipelineData pipelineData = (PipelineData) data; - RunData runData = (RunData)pipelineData; + RunData runData = pipelineData.getRunData(); templateURI = new TemplateURI(runData); } else @@ -147,7 +146,7 @@ public class TemplateLink wantEncoding = conf.getBoolean(TEMPLATE_LINK_ENCODING_KEY, TEMPLATE_LINK_ENCODING_DEFAULT); } - + if (!wantEncoding) { templateURI.clearResponse(); diff --git a/src/java/org/apache/turbine/services/pull/tools/UITool.java b/src/java/org/apache/turbine/services/pull/tools/UITool.java index beb0bc89..ee912b42 100644 --- a/src/java/org/apache/turbine/services/pull/tools/UITool.java +++ b/src/java/org/apache/turbine/services/pull/tools/UITool.java @@ -368,22 +368,21 @@ public class UITool implements ApplicationTool log.debug("UITool scope is global"); setSkin(); } - else if (data instanceof RunData) + else if (data instanceof RunData rd) { log.debug("UITool scope is request"); - setSkin((RunData) data); + setSkin(rd); } - else if (data instanceof PipelineData) + else if (data instanceof PipelineData pipelineData) { - PipelineData pipelineData = (PipelineData) data; - RunData runData = (RunData)pipelineData; + RunData runData = pipelineData.getRunData(); log.debug("UITool scope is request"); setSkin(runData); } - else if (data instanceof User) + else if (data instanceof User u) { log.debug("UITool scope is session"); - setSkin((User) data); + setSkin(u); } } diff --git a/src/java/org/apache/turbine/services/pull/util/DateTimeFormatterTool.java b/src/java/org/apache/turbine/services/pull/util/DateTimeFormatterTool.java index 3ad986d7..8ad2fc1f 100644 --- a/src/java/org/apache/turbine/services/pull/util/DateTimeFormatterTool.java +++ b/src/java/org/apache/turbine/services/pull/util/DateTimeFormatterTool.java @@ -42,8 +42,8 @@ import org.apache.turbine.util.RunData; * This pull tool is used to format {@link TemporalAccessor} and * {@link #map(String, DateTimeFormatter, Locale)} (different flavors) * objects into strings. - * - * This tool extends {@link DateFormatter} to simplify configuration + * + * This tool extends {@link DateFormatter} to simplify configuration * and to allow legacy {@link Date} inputs. * * The methods may throw {@link java.time.temporal.UnsupportedTemporalTypeException} or @@ -63,11 +63,11 @@ public class DateTimeFormatterTool extends DateFormatter /** Fulcrum Localization component */ @TurbineService private LocalizationService localizationService; - + protected Locale locale; - + private boolean overrideFromRequestLocale = false; - + /** * Initialize the application tool. The data parameter holds a different * type depending on how the tool is being instantiated: @@ -80,13 +80,13 @@ public class DateTimeFormatterTool extends DateFormatter * the {@link #getDefaultFormat()} from {@link #getFormatPattern()} * with {@link DateTimeFormatterService#getLocale()} * and zoneId {@link DateTimeFormatterService#getZoneId()} is used. - * + * * Customizations: - * Locale could be fetched from request, if #USE_REQUEST_LOCALE_KEY is set to - * <code>true</code> (by default it is <code>false</code>.Then it will be retrieved either from + * Locale could be fetched from request, if #USE_REQUEST_LOCALE_KEY is set to + * <code>true</code> (by default it is <code>false</code>.Then it will be retrieved either from * {@link RundataLocalizationService#getLocale(RunData)} (if set in urbien role configuration) * or {@link LocalizationService#getLocale(jakarta.servlet.http.HttpServletRequest)}. - * + * * @param data initialization data */ @Override @@ -99,15 +99,15 @@ public class DateTimeFormatterTool extends DateFormatter ServiceManager serviceManager = TurbineServices.getInstance(); dtfs = (DateTimeFormatterService)serviceManager.getService(DateTimeFormatterService.SERVICE_NAME); } - + overrideFromRequestLocale = Turbine.getConfiguration() .getBoolean(USE_REQUEST_LOCALE_KEY, false); // dtfs should be already initialized - if (overrideFromRequestLocale && data instanceof RunData) + if (overrideFromRequestLocale && data instanceof RunData rd) { // Pull necessary information out of RunData while we have // a reference to it. - locale = localizationService.getLocale(((RunData) data).getRequest()); + locale = localizationService.getLocale(rd.getRequest()); log.info("Override {} with request locale {} from {}", dtfs.getLocale(), locale, localizationService); } } @@ -165,7 +165,7 @@ public class DateTimeFormatterTool extends DateFormatter } @Override - public String map( String src, java.time.format.DateTimeFormatter outgoingFormat, + public String map( String src, java.time.format.DateTimeFormatter outgoingFormat, Locale locale, java.time.format.DateTimeFormatter incomingFormat) { return getDtfs().map(src, outgoingFormat, locale, incomingFormat); diff --git a/src/java/org/apache/turbine/services/rundata/DefaultTurbineRunData.java b/src/java/org/apache/turbine/services/rundata/DefaultTurbineRunData.java index 534d8a60..4f383c60 100644 --- a/src/java/org/apache/turbine/services/rundata/DefaultTurbineRunData.java +++ b/src/java/org/apache/turbine/services/rundata/DefaultTurbineRunData.java @@ -167,9 +167,7 @@ public class DefaultTurbineRunData { try { - @SuppressWarnings("unchecked") - T user = (T) session.getAttribute(User.SESSION_KEY); - return user; + return (T) session.getAttribute(User.SESSION_KEY); } catch (ClassCastException e) { @@ -204,7 +202,7 @@ public class DefaultTurbineRunData super(); // a map to hold information to be added to pipelineData - put(Turbine.class, new HashMap<Class<?>, Object>()); + put(Turbine.class, new HashMap<>()); recycle(); } @@ -354,9 +352,7 @@ public class DefaultTurbineRunData @Override public <A extends AccessControlList> A getACL() { - @SuppressWarnings("unchecked") - A acl = (A)get(Turbine.class, TurbineAccessControlList.class); - return acl; + return (A)get(Turbine.class, TurbineAccessControlList.class); } /** @@ -738,9 +734,7 @@ public class DefaultTurbineRunData @Override public <T extends User> T getUser() { - @SuppressWarnings("unchecked") - T user = (T)get(Turbine.class, User.class); - return user; + return (T)get(Turbine.class, User.class); } /** diff --git a/src/java/org/apache/turbine/services/rundata/TurbineRunDataService.java b/src/java/org/apache/turbine/services/rundata/TurbineRunDataService.java index f4ba35ea..1aadb487 100644 --- a/src/java/org/apache/turbine/services/rundata/TurbineRunDataService.java +++ b/src/java/org/apache/turbine/services/rundata/TurbineRunDataService.java @@ -24,11 +24,6 @@ import java.util.Locale; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import jakarta.servlet.ServletConfig; -import jakarta.servlet.ServletContext; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; - import org.apache.commons.configuration2.Configuration; import org.apache.fulcrum.parser.CookieParser; import org.apache.fulcrum.parser.DefaultCookieParser; @@ -46,6 +41,11 @@ import org.apache.turbine.util.ServerData; import org.apache.turbine.util.TurbineException; import org.apache.turbine.util.TurbineRuntimeException; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + /** * The RunData Service provides the implementations for RunData and * related interfaces required by request processing. It supports @@ -104,8 +104,7 @@ public class TurbineRunDataService throws InitializationException { // Create a default configuration. - String[] def = new String[] - { + String[] def = { DEFAULT_RUN_DATA, DEFAULT_PARAMETER_PARSER, DEFAULT_COOKIE_PARSER @@ -118,8 +117,7 @@ public class TurbineRunDataService { String key,value; String[] config; - String[] plist = new String[] - { + String[] plist = { RUN_DATA_KEY, PARAMETER_PARSER_KEY, COOKIE_PARSER_KEY @@ -295,10 +293,10 @@ public class TurbineRunDataService @Override public boolean putRunData(RunData data) { - if (data instanceof TurbineRunData) + if (data instanceof TurbineRunData trd) { - parserService.putParser(((TurbineRunData) data).getParameterParser()); - parserService.putParser(((TurbineRunData) data).getCookieParser()); + parserService.putParser(trd.getParameterParser()); + parserService.putParser(trd.getCookieParser()); return pool.putInstance(data); } diff --git a/src/java/org/apache/turbine/services/schedule/AbstractSchedulerService.java b/src/java/org/apache/turbine/services/schedule/AbstractSchedulerService.java index c4ddba9f..783d04b2 100644 --- a/src/java/org/apache/turbine/services/schedule/AbstractSchedulerService.java +++ b/src/java/org/apache/turbine/services/schedule/AbstractSchedulerService.java @@ -47,7 +47,7 @@ public abstract class AbstractSchedulerService extends TurbineBaseService implem protected JobQueue<JobEntry> scheduleQueue = null; /** Current status of the scheduler */ - private AtomicBoolean enabled = new AtomicBoolean(false); + private final AtomicBoolean enabled = new AtomicBoolean(false); /** The housekeeping thread. */ protected Thread houseKeepingThread; diff --git a/src/java/org/apache/turbine/services/schedule/JobEntryNonPersistent.java b/src/java/org/apache/turbine/services/schedule/JobEntryNonPersistent.java index ed14fc52..0e2a6981 100644 --- a/src/java/org/apache/turbine/services/schedule/JobEntryNonPersistent.java +++ b/src/java/org/apache/turbine/services/schedule/JobEntryNonPersistent.java @@ -102,9 +102,9 @@ public class JobEntryNonPersistent extends AbstractJobEntry @Override public boolean equals(Object obj) { - if (obj instanceof JobEntry) + if (obj instanceof JobEntry je) { - return compareTo((JobEntry)obj) == 0; + return compareTo(je) == 0; } return false; diff --git a/src/java/org/apache/turbine/services/schedule/JobEntryQuartz.java b/src/java/org/apache/turbine/services/schedule/JobEntryQuartz.java index 277c98d1..340dd23e 100644 --- a/src/java/org/apache/turbine/services/schedule/JobEntryQuartz.java +++ b/src/java/org/apache/turbine/services/schedule/JobEntryQuartz.java @@ -45,7 +45,7 @@ public class JobEntryQuartz implements JobEntry, Job private JobDetail jobDetail; private String task; private boolean isnew = true; - private AtomicBoolean active = new AtomicBoolean(false); + private final AtomicBoolean active = new AtomicBoolean(false); /** * the default Quartz schedule group name for Turbine jobs @@ -234,7 +234,7 @@ public class JobEntryQuartz implements JobEntry, Job @Override public void execute(JobExecutionContext context) throws JobExecutionException { - if (active.compareAndSet(false, true) == false) + if (!active.compareAndSet(false, true)) { return; } diff --git a/src/java/org/apache/turbine/services/schedule/JobQueue.java b/src/java/org/apache/turbine/services/schedule/JobQueue.java index 47a5697d..5a5a3edb 100644 --- a/src/java/org/apache/turbine/services/schedule/JobQueue.java +++ b/src/java/org/apache/turbine/services/schedule/JobQueue.java @@ -1,5 +1,7 @@ package org.apache.turbine.services.schedule; +import java.util.Comparator; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -45,7 +47,7 @@ public class JobQueue<J extends JobEntry> */ public JobQueue() { - queue = new ConcurrentSkipListSet<J>((o1, o2) -> Long.compare(o1.getNextRuntime(), o2.getNextRuntime())); + queue = new ConcurrentSkipListSet<>(Comparator.comparing(J::getNextRuntime)); } /** @@ -58,7 +60,7 @@ public class JobQueue<J extends JobEntry> { return queue.pollFirst(); } - + /** * Return the next job of the top of the queue or <code>null</code> if * there are no jobs in the queue. @@ -91,7 +93,7 @@ public class JobQueue<J extends JobEntry> { return jobEntry; } - } + } } return null; } diff --git a/src/java/org/apache/turbine/services/schedule/QuartzSchedulerService.java b/src/java/org/apache/turbine/services/schedule/QuartzSchedulerService.java index 10cd7edd..d59c05c8 100644 --- a/src/java/org/apache/turbine/services/schedule/QuartzSchedulerService.java +++ b/src/java/org/apache/turbine/services/schedule/QuartzSchedulerService.java @@ -116,9 +116,7 @@ public class QuartzSchedulerService .forJob(jd) .build(); - JobEntryQuartz jeq = new JobEntryQuartz(t, jd); - - return jeq; + return new JobEntryQuartz(t, jd); } catch (ParseException e) { @@ -376,9 +374,9 @@ public class QuartzSchedulerService */ private JobEntryQuartz downCast(JobEntry je) throws TurbineException { - if (je instanceof JobEntryQuartz) + if (je instanceof JobEntryQuartz jeq) { - return (JobEntryQuartz)je; + return jeq; } else { @@ -407,8 +405,7 @@ public class QuartzSchedulerService * @return A JobEntryQuartz. */ public JobEntryQuartz buildJobEntry(Trigger trigger, JobDetail jd) { - JobEntryQuartz job = new JobEntryQuartz(trigger, jd); - return job; + return new JobEntryQuartz(trigger, jd); } } diff --git a/src/java/org/apache/turbine/services/schedule/TorqueSchedulerService.java b/src/java/org/apache/turbine/services/schedule/TorqueSchedulerService.java index 02b5a855..fd96e925 100644 --- a/src/java/org/apache/turbine/services/schedule/TorqueSchedulerService.java +++ b/src/java/org/apache/turbine/services/schedule/TorqueSchedulerService.java @@ -158,9 +158,9 @@ public class TorqueSchedulerService extends AbstractSchedulerService scheduleQueue.modify(je); } - if (je instanceof JobEntryTorque) + if (je instanceof JobEntryTorque jet) { - ((JobEntryTorque)je).save(); + jet.save(); } restart(); diff --git a/src/java/org/apache/turbine/services/security/DefaultSecurityService.java b/src/java/org/apache/turbine/services/security/DefaultSecurityService.java index 7c1e127d..7e320a71 100644 --- a/src/java/org/apache/turbine/services/security/DefaultSecurityService.java +++ b/src/java/org/apache/turbine/services/security/DefaultSecurityService.java @@ -76,7 +76,7 @@ public class DefaultSecurityService implements SecurityService { /** The number of threads concurrently reading security information */ - private AtomicInteger readerCount = new AtomicInteger(0); + private final AtomicInteger readerCount = new AtomicInteger(0); /** The instance of UserManager the SecurityService uses */ private UserManager userManager = null; @@ -642,9 +642,7 @@ public class DefaultSecurityService } } } - @SuppressWarnings("unchecked") - G g = (G)globalGroup; - return g; + return (G)globalGroup; } /** @@ -694,9 +692,9 @@ public class DefaultSecurityService throws DataBackendException, UnknownEntityException { R role = roleManager.getRoleByName(name); - if (role instanceof TurbineRole) + if (role instanceof TurbineRole tr) { - ((TurbineRole)role).setPermissions(getPermissions(role)); + tr.setPermissions(getPermissions(role)); } return role; } @@ -716,9 +714,9 @@ public class DefaultSecurityService UnknownEntityException { R role = roleManager.getRoleById(Integer.valueOf(id)); - if (role instanceof TurbineRole) + if (role instanceof TurbineRole tr) { - ((TurbineRole)role).setPermissions(getPermissions(role)); + tr.setPermissions(getPermissions(role)); } return role; } diff --git a/src/java/org/apache/turbine/services/security/DefaultUserManager.java b/src/java/org/apache/turbine/services/security/DefaultUserManager.java index 32b73dd0..d3662120 100644 --- a/src/java/org/apache/turbine/services/security/DefaultUserManager.java +++ b/src/java/org/apache/turbine/services/security/DefaultUserManager.java @@ -97,9 +97,7 @@ public class DefaultUserManager implements UserManager */ protected <U extends User> U wrap(TurbineUser user) { - @SuppressWarnings("unchecked") - U u = (U) getUserWrapper(user); - return u; + return (U) getUserWrapper(user); } /** @@ -114,8 +112,8 @@ public class DefaultUserManager implements UserManager { try { - Object params[] = new Object[] { user }; - String signature[] = new String[] { TurbineUser.class.getName() }; + Object params[] = { user }; + String signature[] = { TurbineUser.class.getName() }; return (U) factoryService.getInstance(getUserWrapperClass(), params, signature); } catch (Exception e) @@ -168,8 +166,8 @@ public class DefaultUserManager implements UserManager // should provide default constructor TurbineUser turbineUser = umDelegate.getUserInstance(); //(TurbineUser) factoryService.getInstance(userClass); - Object params[] = new Object[] { turbineUser }; - String signature[] = new String[] { TurbineUser.class.getName() }; + Object params[] = { turbineUser }; + String signature[] = { TurbineUser.class.getName() }; // Just check if exceptions would occur factoryService.getInstance(userWrapperClass, params, signature); @@ -258,13 +256,11 @@ public class DefaultUserManager implements UserManager { UserSet<org.apache.fulcrum.security.entity.User> uset = umDelegate.retrieveUserList(criteria); - List<User> userList = uset.stream() + return uset.stream() .map(u -> (TurbineUser) u) .map(this::wrap) .map(u -> (User)u) .collect(Collectors.toList()); - - return userList; } /** @@ -318,7 +314,7 @@ public class DefaultUserManager implements UserManager throw new DataBackendException("Could not serialize permanent storage", e); } - umDelegate.saveUser(((TurbineUserDelegate)user).getUserDelegate()); + umDelegate.saveUser(user.getUserDelegate()); } /** @@ -421,7 +417,7 @@ public class DefaultUserManager implements UserManager throw new UnknownEntityException("user is null"); } umDelegate.changePassword( - ((TurbineUserDelegate)user).getUserDelegate(), + user.getUserDelegate(), oldPassword, newPassword); } diff --git a/src/java/org/apache/turbine/services/servlet/TurbineServletService.java b/src/java/org/apache/turbine/services/servlet/TurbineServletService.java index 467437d2..550b42a4 100644 --- a/src/java/org/apache/turbine/services/servlet/TurbineServletService.java +++ b/src/java/org/apache/turbine/services/servlet/TurbineServletService.java @@ -138,8 +138,7 @@ public class TurbineServletService } InputStream is = null; - is = servletContext.getResourceAsStream(uri); - return is; + return servletContext.getResourceAsStream(uri); } /** diff --git a/src/java/org/apache/turbine/services/template/TurbineTemplateService.java b/src/java/org/apache/turbine/services/template/TurbineTemplateService.java index 9ef3f919..50515a25 100644 --- a/src/java/org/apache/turbine/services/template/TurbineTemplateService.java +++ b/src/java/org/apache/turbine/services/template/TurbineTemplateService.java @@ -717,17 +717,17 @@ public class TurbineTemplateService // out of the Template Service. mapperRegistry = new Mapper[TEMPLATE_TYPES]; - String [] mapperNames = new String [] { + String [] mapperNames = { Page.NAME, Screen.NAME, Layout.NAME, Navigation.NAME, LAYOUT_TEMPLATE_NAME, SCREEN_TEMPLATE_NAME, NAVIGATION_TEMPLATE_NAME }; - Class<?> [] mapperKeys = new Class<?> [] { + Class<?> [] mapperKeys = { Page.class, Screen.class, Layout.class, Navigation.class, Layout.class, Screen.class, Navigation.class }; - String [] mapperClasses = new String [] { + String [] mapperClasses = { DirectMapper.class.getName(), ClassMapper.class.getName(), ClassMapper.class.getName(), @@ -754,7 +754,7 @@ public class TurbineTemplateService mapperLoader[SCREEN_TEMPLATE_KEY] = null; mapperLoader[NAVIGATION_TEMPLATE_KEY] = null; - String [] mapperDefaultProperty = new String [] { + String [] mapperDefaultProperty = { TemplateEngineService.DEFAULT_PAGE, TemplateEngineService.DEFAULT_SCREEN, TemplateEngineService.DEFAULT_LAYOUT, @@ -764,9 +764,9 @@ public class TurbineTemplateService TemplateEngineService.DEFAULT_NAVIGATION_TEMPLATE }; - char [] mapperSeparator = new char [] { '.', '.', '.', '.', '/', '/', '/' }; + char [] mapperSeparator = { '.', '.', '.', '.', '/', '/', '/' }; - String [] mapperPrefix = new String [] { + String [] mapperPrefix = { null, null, null, null, Layout.PREFIX, Screen.PREFIX, @@ -801,14 +801,14 @@ public class TurbineTemplateService tm.setDefaultProperty(mapperDefaultProperty[i]); tm.setSeparator(mapperSeparator[i]); - if (mapperLoader[i] != null && tm instanceof ClassMapper) + if (mapperLoader[i] != null && tm instanceof ClassMapper cm) { - ((ClassMapper) tm).setLoader(mapperLoader[i]); + cm.setLoader(mapperLoader[i]); } - if (mapperPrefix[i] != null && tm instanceof BaseTemplateMapper) + if (mapperPrefix[i] != null && tm instanceof BaseTemplateMapper btm) { - ((BaseTemplateMapper) tm).setPrefix(mapperPrefix[i]); + btm.setPrefix(mapperPrefix[i]); } registerMapper(i, tm); diff --git a/src/java/org/apache/turbine/services/ui/TurbineUIService.java b/src/java/org/apache/turbine/services/ui/TurbineUIService.java index c1cc421d..1f82f8e1 100644 --- a/src/java/org/apache/turbine/services/ui/TurbineUIService.java +++ b/src/java/org/apache/turbine/services/ui/TurbineUIService.java @@ -150,7 +150,7 @@ public class TurbineUIService /** * The skin Properties store. */ - private ConcurrentHashMap<String, Properties> skins = new ConcurrentHashMap<>(); + private final ConcurrentHashMap<String, Properties> skins = new ConcurrentHashMap<>(); /** * Refresh the service by clearing all skins. diff --git a/src/java/org/apache/turbine/services/urlmapper/TurbineURLMapperService.java b/src/java/org/apache/turbine/services/urlmapper/TurbineURLMapperService.java index 9d571f50..82efd50b 100644 --- a/src/java/org/apache/turbine/services/urlmapper/TurbineURLMapperService.java +++ b/src/java/org/apache/turbine/services/urlmapper/TurbineURLMapperService.java @@ -165,7 +165,7 @@ public class TurbineURLMapperService if (entryKeys.containsAll(keys)) { Matcher matcher = NAMED_GROUPS_PATTERN.matcher(urlMap.getUrlPattern().pattern()); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); while (matcher.find()) { @@ -191,8 +191,8 @@ public class TurbineURLMapperService } } - matcher.appendTail(sb); - + new StringBuilder(matcher.appendTail(sb).toString()); + implicitKeysFound.forEach(key -> { pathInfo.removeIf(uriParam -> key.equals(uriParam.getKey())); queryData.removeIf(uriParam -> key.equals(uriParam.getKey())); @@ -200,11 +200,11 @@ public class TurbineURLMapperService // Clean up uri.setScriptName(MULTI_SLASH_PATTERN.matcher(sb).replaceAll("/").replaceFirst( "/$", "" )); - + break; } } - + log.debug("mapped to uri: {} ", uri); } @@ -241,7 +241,7 @@ public class TurbineURLMapperService // remove ignore parameters urlMap.getIgnoreParameters().keySet() .forEach(pp::remove); - + log.debug("mapped {} params from url {} ", pp.getKeys().length, url); break; diff --git a/src/java/org/apache/turbine/services/velocity/TurbineVelocityService.java b/src/java/org/apache/turbine/services/velocity/TurbineVelocityService.java index fce69f17..b24caeae 100644 --- a/src/java/org/apache/turbine/services/velocity/TurbineVelocityService.java +++ b/src/java/org/apache/turbine/services/velocity/TurbineVelocityService.java @@ -182,8 +182,7 @@ public class TurbineVelocityService Context globalContext = pullModelActive ? pullService.getGlobalContext() : null; - Context ctx = new VelocityContext(globalContext); - return ctx; + return new VelocityContext(globalContext); } /** @@ -414,9 +413,9 @@ public class TurbineVelocityService Charset charset = null; Object data = context.get(VelocityService.RUNDATA_KEY); - if ((data != null) && (data instanceof RunData)) + if (data != null && data instanceof RunData rd) { - charset = ((RunData) data).getCharset(); + charset = rd.getCharset(); } return charset == null ? defaultOutputEncoding : charset; @@ -433,9 +432,9 @@ public class TurbineVelocityService Charset encoding = null; Object data = context.get(VelocityService.RUNDATA_KEY); - if ((data != null) && (data instanceof RunData) && (((RunData) data).getTemplateEncoding() != null) ) + if (data != null && data instanceof RunData rd && rd.getTemplateEncoding() != null) { - encoding = Charset.forName(((RunData) data).getTemplateEncoding()); + encoding = Charset.forName(rd.getTemplateEncoding()); } return encoding != null ? encoding : defaultInputEncoding; @@ -508,9 +507,9 @@ public class TurbineVelocityService if (!key.endsWith(RESOURCE_LOADER_PATH)) { Object value = conf.getProperty(key); - if (value instanceof List<?>) + if (value instanceof List<?> list) { - for (Object name2 : ((List<?>) value)) + for (Object name2 : list) { velocity.addProperty(key, name2); } diff --git a/src/java/org/apache/turbine/util/FormMessages.java b/src/java/org/apache/turbine/util/FormMessages.java index e796d014..a13ad5ce 100644 --- a/src/java/org/apache/turbine/util/FormMessages.java +++ b/src/java/org/apache/turbine/util/FormMessages.java @@ -1,7 +1,5 @@ package org.apache.turbine.util; -import java.util.ArrayList; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -21,8 +19,11 @@ import java.util.ArrayList; * under the License. */ -import java.util.Hashtable; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; /** * Used for adding and accessing messages that relate to a specific form and field. Allows to query for messages by form @@ -33,23 +34,23 @@ import java.util.List; */ public class FormMessages { - private final Hashtable<String, List<String>> forms_messages; + private final Map<String, List<String>> forms_messages; - private final Hashtable<String, List<String>> fields_messages; + private final Map<String, List<String>> fields_messages; - private final Hashtable<String, List<String>> messages_fields; + private final Map<String, List<String>> messages_fields; - private final Hashtable<String, List<String>> forms_fields; + private final Map<String, List<String>> forms_fields; /** * Constructor. */ public FormMessages() { - forms_messages = new Hashtable<>(); - fields_messages = new Hashtable<>(); - messages_fields = new Hashtable<>(); - forms_fields = new Hashtable<>(); + forms_messages = new HashMap<>(); + fields_messages = new HashMap<>(); + messages_fields = new HashMap<>(); + forms_fields = new HashMap<>(); } /** @@ -83,38 +84,27 @@ public class FormMessages /** * Adds a pair key/value to a table, making sure not to add duplicate keys. * - * @param table A Hashtable. + * @param table A Map. * @param key A String with the key. * @param value A String with value. */ - private void addValue( Hashtable<String, List<String>> table, String key, String value ) + private void addValue( Map<String, List<String>> table, String key, String value ) { - List<String> values; - - if ( !table.containsKey( key ) ) + List<String> values = table.computeIfAbsent(key, k -> new ArrayList<>()); + if (!values.contains( value)) { - values = new ArrayList<>(); - values.add( value ); - table.put( key, values ); - } - else - { - values = table.get( key ); - if ( !values.contains( value ) ) - { - values.add( value ); - } + values.add(value); } } /** * Gets a pair key/value from a table. * - * @param table A Hashtable. + * @param table A Map. * @param key A String with the key. * @return A List with the pair key/value, or null. */ - private final List<String> getValues( Hashtable<String, List<String>> table, String key ) + private final List<String> getValues( Map<String, List<String>> table, String key ) { return table.get( key ); } @@ -127,28 +117,25 @@ public class FormMessages */ public FormMessage[] getFormMessages( String formName ) { - List<String> messages, fields; - String messageName, fieldName; - messages = getValues( forms_messages, formName ); + List<String> messages = getValues( forms_messages, formName ); if ( messages != null ) { - FormMessage[] result = new FormMessage[messages.size()]; - for ( int i = 0; i < messages.size(); i++ ) - { - result[i] = new FormMessage( formName ); - messageName = messages.get( i ); - result[i].setMessage( messageName ); - fields = getValues( messages_fields, messageName ); - for (String field : fields) - { - fieldName = field; - if ( formHasField( formName, fieldName ) ) - { - result[i].setFieldName( fieldName ); - } - } - } - return result; + return messages.stream() + .map(message -> { + FormMessage fm = new FormMessage(formName); + fm.setMessage(message); + List<String> fields = getValues( messages_fields, message); + fields.forEach(field -> { + if (formHasField(formName, field)) + { + fm.setFieldName(field); + } + }); + + return fm; + }) + .collect(Collectors.toList()) + .toArray(new FormMessage[messages.size()]); } return null; } diff --git a/src/java/org/apache/turbine/util/HttpUtils.java b/src/java/org/apache/turbine/util/HttpUtils.java index c142cce8..84d3fcbc 100644 --- a/src/java/org/apache/turbine/util/HttpUtils.java +++ b/src/java/org/apache/turbine/util/HttpUtils.java @@ -45,7 +45,7 @@ public class HttpUtils * Validates only external key (name), as internal key may also contain colon and space. */ private static final String CHARACTERS_NOT_ALLOWED_IN_KEY = "[^\\w_/\\.-]"; - + private static final Pattern CNAIK_PATTERN = Pattern.compile(CHARACTERS_NOT_ALLOWED_IN_KEY); /** * The date format to use for HTTP Dates. @@ -91,11 +91,11 @@ public class HttpUtils response.setDateHeader("Expires", System.currentTimeMillis() + expiry); } } - + /** * Check, if there is any not allowed {@value #CHARACTERS_NOT_ALLOWED_IN_KEY} * in parameters, eg. Turbine keys like actions, screens, layouts. - * + * * @param parameter or key to be checked * @return True, if it contains any non allowed characters */ @@ -103,15 +103,15 @@ public class HttpUtils Matcher testMatcher = CNAIK_PATTERN.matcher(parameter); return testMatcher.find(); } - + /** * Cleans parameter/key from disallowed characters defined in {@link #CHARACTERS_NOT_ALLOWED_IN_KEY}. - * + * * @param parameter to be cleaned * @return the cleaned parameter */ public static String getCleanedKey(String parameter) { return parameter.replaceAll(CHARACTERS_NOT_ALLOWED_IN_KEY,""); } - + } diff --git a/src/java/org/apache/turbine/util/ObjectUtils.java b/src/java/org/apache/turbine/util/ObjectUtils.java index 57e6e014..4769265e 100644 --- a/src/java/org/apache/turbine/util/ObjectUtils.java +++ b/src/java/org/apache/turbine/util/ObjectUtils.java @@ -60,14 +60,14 @@ public abstract class ObjectUtils { byte[] byteArray = null; Map<String, Object> mapCopy = new HashMap<>(map); - + // Remove all entries that are not serializable for (Iterator<Map.Entry<String, Object>> i = mapCopy.entrySet().iterator(); i.hasNext();) { Map.Entry<String, Object> entry = i.next(); if (! (entry.getValue() instanceof Serializable)) { - i.remove(); + i.remove(); log.warn("Skipping serialization, value is not serializable: " + entry.getValue()); } } @@ -100,7 +100,7 @@ public abstract class ObjectUtils if (objectData != null) { final String filterPattern = Turbine.getConfiguration().getString(TurbineConstants.SESSION_OBJECTINPUTFILTER); - + try (ByteArrayInputStream bin = new ByteArrayInputStream(objectData); ObjectInputStream in = new ObjectInputStream(bin)) { @@ -109,7 +109,7 @@ public abstract class ObjectUtils { in.setObjectInputFilter(ObjectInputFilter.Config.createFilter(filterPattern)); } - + // If objectData has not been initialized, an // exception will occur. object = (T)in.readObject(); diff --git a/src/java/org/apache/turbine/util/SecurityCheck.java b/src/java/org/apache/turbine/util/SecurityCheck.java index 16f5eb10..78c117e3 100644 --- a/src/java/org/apache/turbine/util/SecurityCheck.java +++ b/src/java/org/apache/turbine/util/SecurityCheck.java @@ -48,9 +48,9 @@ import org.apache.turbine.services.TurbineServices; */ public class SecurityCheck { - private String message; + private final String message; - private String failScreen; + private final String failScreen; private RunData data = null; @@ -60,7 +60,7 @@ public class SecurityCheck * Holds information if a missing Permission or Role should be created and granted on-the-fly. * This is good behavior, if these change a lot. */ - private boolean initialize; + private final boolean initialize; /** * Constructor. diff --git a/src/java/org/apache/turbine/util/TurbineConfig.java b/src/java/org/apache/turbine/util/TurbineConfig.java index 5e0d317d..402ec3ba 100644 --- a/src/java/org/apache/turbine/util/TurbineConfig.java +++ b/src/java/org/apache/turbine/util/TurbineConfig.java @@ -85,7 +85,7 @@ import org.apache.turbine.pipeline.PipelineData; * </p> * * TODO Make this class enforce the lifecycle contracts - * + * * @see <a href="https://jakarta.ee/specifications/servlet/6.1/jakarta-servlet-spec-6.1">Java Servlet Spec v6.1</a> * * @author <a href="mailto:[email protected]">Quinton McCombs</a> @@ -190,7 +190,7 @@ public class TurbineConfig */ public TurbineConfig(String path, String properties) { - this(path, new HashMap<String, String>(1)); + this(path, new HashMap<>(1)); initParams.put(PROPERTIES_PATH_KEY, properties); } @@ -921,7 +921,7 @@ public class TurbineConfig @Override public void setResponseCharacterEncoding(String encoding) { - + } } diff --git a/src/java/org/apache/turbine/util/TurbineXmlConfig.java b/src/java/org/apache/turbine/util/TurbineXmlConfig.java index 8e83be62..173f0de5 100644 --- a/src/java/org/apache/turbine/util/TurbineXmlConfig.java +++ b/src/java/org/apache/turbine/util/TurbineXmlConfig.java @@ -94,7 +94,7 @@ public class TurbineXmlConfig */ public TurbineXmlConfig(String path, Map<String, String> initParams) { - this(path, new HashMap<String, Object>(0), initParams); + this(path, new HashMap<>(0), initParams); } /** @@ -108,7 +108,7 @@ public class TurbineXmlConfig */ public TurbineXmlConfig(String path, String config) { - this(path, new HashMap<String, String>(1)); + this(path, new HashMap<>(1)); initParams.put(CONFIGURATION_PATH_KEY, config); } } diff --git a/src/java/org/apache/turbine/util/template/TemplateInfo.java b/src/java/org/apache/turbine/util/template/TemplateInfo.java index cbd7c78c..4309506f 100644 --- a/src/java/org/apache/turbine/util/template/TemplateInfo.java +++ b/src/java/org/apache/turbine/util/template/TemplateInfo.java @@ -132,8 +132,7 @@ public class TemplateInfo */ public String getLayoutTemplate() { - String value = getString(TemplateInfo.LAYOUT_TEMPLATE); - return value; + return getString(TemplateInfo.LAYOUT_TEMPLATE); } /** diff --git a/src/java/org/apache/turbine/util/uri/URIParam.java b/src/java/org/apache/turbine/util/uri/URIParam.java index 570e99d7..fc603448 100644 --- a/src/java/org/apache/turbine/util/uri/URIParam.java +++ b/src/java/org/apache/turbine/util/uri/URIParam.java @@ -90,11 +90,13 @@ public class URIParam public boolean equals(Object obj) { if (this == obj) + { return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) + } + if ((obj == null) || (getClass() != obj.getClass())) + { return false; + } URIParam other = (URIParam) obj; return Objects.equals(getKey(), other.getKey()) || diff --git a/src/java/org/apache/turbine/util/velocity/VelocityEmail.java b/src/java/org/apache/turbine/util/velocity/VelocityEmail.java index 1eb9a6dd..6926a802 100644 --- a/src/java/org/apache/turbine/util/velocity/VelocityEmail.java +++ b/src/java/org/apache/turbine/util/velocity/VelocityEmail.java @@ -265,7 +265,7 @@ public class VelocityEmail extends SimpleEmail if (wordWrap > 0) { body = WordUtils.wrap(body, wordWrap, - System.getProperty("line.separator"), false); + System.lineSeparator(), false); } setMsg(body); diff --git a/src/test/org/apache/turbine/ConfigurationTest.java b/src/test/org/apache/turbine/ConfigurationTest.java index fb15f8ba..4716d026 100644 --- a/src/test/org/apache/turbine/ConfigurationTest.java +++ b/src/test/org/apache/turbine/ConfigurationTest.java @@ -59,8 +59,14 @@ public class ConfigurationTest extends BaseTestCase @After public void close() { - if (tc != null) tc.dispose(); - if (txc != null) txc.dispose(); + if (tc != null) + { + tc.dispose(); + } + if (txc != null) + { + txc.dispose(); + } } @Test diff --git a/src/test/org/apache/turbine/modules/ActionLoaderTest.java b/src/test/org/apache/turbine/modules/ActionLoaderTest.java index b540ac19..de0ff41e 100644 --- a/src/test/org/apache/turbine/modules/ActionLoaderTest.java +++ b/src/test/org/apache/turbine/modules/ActionLoaderTest.java @@ -332,7 +332,7 @@ public class ActionLoaderTest extends BaseTestCase fail("Should not have thrown an exception."); } } - + @Test public void testDoPerformWithExtendedServiceInjection() throws Exception { diff --git a/src/test/org/apache/turbine/modules/actions/VelocityActionWithExtendedServiceInjection.java b/src/test/org/apache/turbine/modules/actions/VelocityActionWithExtendedServiceInjection.java index 9aec0ba3..48187888 100644 --- a/src/test/org/apache/turbine/modules/actions/VelocityActionWithExtendedServiceInjection.java +++ b/src/test/org/apache/turbine/modules/actions/VelocityActionWithExtendedServiceInjection.java @@ -30,9 +30,9 @@ import org.apache.turbine.services.ServiceWithServiceInjection; import org.apache.velocity.context.Context; /** - * Annnotating even an assembler as TurbineService on class level we could omit + * Annnotating even an assembler as TurbineService on class level we could omit * annotations for fields if class is a Turbine service. - * + * * This would be quite experimental. */ //@TurbineService @@ -41,10 +41,10 @@ public class VelocityActionWithExtendedServiceInjection extends VelocityAction private static Log log = LogFactory.getLog(VelocityActionWithExtendedServiceInjection.class); // Test for class level SERVICE_NAME in ServiceWithServiceInjection - // Annotation could be omitted as the class is annotated could be omitted + // Annotation could be omitted as the class is annotated could be omitted @TurbineService private ServiceWithServiceInjection serviceWithServiceInjection; - + /** * Default action is nothing. diff --git a/src/test/org/apache/turbine/om/MockRetrieverFactory.java b/src/test/org/apache/turbine/om/MockRetrieverFactory.java index 33e4539e..cc448f4f 100644 --- a/src/test/org/apache/turbine/om/MockRetrieverFactory.java +++ b/src/test/org/apache/turbine/om/MockRetrieverFactory.java @@ -35,7 +35,7 @@ public class MockRetrieverFactory implements RetrieverFactory @Override public Retriever getInstance(String className) throws Exception { - return key -> new String(key); + return String::new; } } diff --git a/src/test/org/apache/turbine/om/OMToolTest.java b/src/test/org/apache/turbine/om/OMToolTest.java index ab7bf33a..4d6ee7db 100644 --- a/src/test/org/apache/turbine/om/OMToolTest.java +++ b/src/test/org/apache/turbine/om/OMToolTest.java @@ -23,7 +23,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import org.apache.turbine.util.TurbineConfig; import org.junit.AfterClass; @@ -76,7 +76,7 @@ public class OMToolTest { Object testString1 = om.get("test1", "testString"); assertNotNull("Object should not be null", testString1); - assertTrue("Object should be a string", testString1 instanceof String); + assertInstanceOf(String.class, testString1, "Object should be a string"); assertEquals("Object should be a string", "testString", testString1); Object testString2 = om.get("test1", "testString"); assertNotNull("Object should not be null", testString2); diff --git a/src/test/org/apache/turbine/pipeline/PipelineCreationTest.java b/src/test/org/apache/turbine/pipeline/PipelineCreationTest.java index 8809a9d2..a3ee3e38 100644 --- a/src/test/org/apache/turbine/pipeline/PipelineCreationTest.java +++ b/src/test/org/apache/turbine/pipeline/PipelineCreationTest.java @@ -1,39 +1,18 @@ package org.apache.turbine.pipeline; -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; - +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import java.io.StringReader; import java.io.StringWriter; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import jakarta.xml.bind.JAXBContext; import jakarta.xml.bind.Marshaller; import jakarta.xml.bind.Unmarshaller; -import org.junit.jupiter.api.BeforeEach; - -import org.junit.jupiter.api.Test; - /** * Tests TurbinePipeline. * @@ -59,27 +38,29 @@ public class PipelineCreationTest Marshaller marshaller = context.createMarshaller(); StringWriter writer = new StringWriter(); marshaller.marshal(pipeline, writer); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" - + "<pipeline><valves>" - + "<valve>org.apache.turbine.pipeline.SimpleValve</valve>" - + "<valve>org.apache.turbine.pipeline.DetermineActionValve</valve>" - + "</valves></pipeline>", writer.toString()); + assertEquals(""" + <?xml version="1.0" encoding="UTF-8" standalone="yes"?>\ + <pipeline><valves>\ + <valve>org.apache.turbine.pipeline.SimpleValve</valve>\ + <valve>org.apache.turbine.pipeline.DetermineActionValve</valve>\ + </valves></pipeline>""", writer.toString()); } @Test public void testReadingPipeline() throws Exception { - String xml = "<pipeline name=\"default\"><valves>" - + "<valve>org.apache.turbine.pipeline.SimpleValve</valve>" - + "<valve>org.apache.turbine.pipeline.DetermineActionValve</valve>" - + "</valves></pipeline>"; + String xml = """ + <pipeline name="default"><valves>\ + <valve>org.apache.turbine.pipeline.SimpleValve</valve>\ + <valve>org.apache.turbine.pipeline.DetermineActionValve</valve>\ + </valves></pipeline>"""; JAXBContext context = JAXBContext.newInstance(TurbinePipeline.class); Unmarshaller unmarshaller = context.createUnmarshaller(); StringReader reader = new StringReader(xml); Pipeline pipeline = (Pipeline) unmarshaller.unmarshal(reader); assertEquals(2, pipeline.getValves().length); - assertTrue(pipeline.getValves()[0] instanceof SimpleValve); - assertTrue(pipeline.getValves()[1] instanceof DetermineActionValve); + assertInstanceOf(SimpleValve.class, pipeline.getValves()[0]); + assertInstanceOf(DetermineActionValve.class, pipeline.getValves()[1]); } } diff --git a/src/test/org/apache/turbine/services/ServiceWithServiceInjection.java b/src/test/org/apache/turbine/services/ServiceWithServiceInjection.java index 0b801ea4..f619ee5c 100644 --- a/src/test/org/apache/turbine/services/ServiceWithServiceInjection.java +++ b/src/test/org/apache/turbine/services/ServiceWithServiceInjection.java @@ -28,8 +28,8 @@ import org.apache.commons.logging.LogFactory; import org.apache.fulcrum.localization.LocalizationService; import org.apache.turbine.annotation.TurbineService; /** - * This service is used for testing injection of services in fields and methods and class level declaration of - * {@link TurbineService} without interface. + * This service is used for testing injection of services in fields and methods and class level declaration of + * {@link TurbineService} without interface. * * @author <a href="mailto:[email protected]">Georg Kallidis</a> */ @@ -38,36 +38,36 @@ public class ServiceWithServiceInjection extends MethodAnnotatedTurbineBaseServi { // will be checked before ROLE static final String SERVICE_NAME = "ServiceWithService"; - + String ROLE = ServiceWithServiceInjection.class.getName(); - + private static Log log = LogFactory.getLog(ServiceWithServiceInjection.class); - + // Test for implicit SERVICE_NAME // we need the declaration as this is not by default a Turbine Service @TurbineService private LocalizationService localizationService; - + static private ServiceWithServiceInjection2 serviceWithServiceInjection2; - - + + // Test for method injected class level SERVICE_NAME // Annotation could be omitted as the class is annotated @TurbineService public void setServiceWithServiceInjection2(ServiceWithServiceInjection2 serviceWithServiceInjection) { serviceWithServiceInjection2 = serviceWithServiceInjection; } - + /** * Initializes the service. */ @Override - public void initialize() throws Exception + public void initialize() throws Exception { log.debug("Calling initializable()"); // do not call AnnotationProcessor.process(this); here as it will result in an endless looping; } - + /** * Initializes the service. */ @@ -78,8 +78,8 @@ public class ServiceWithServiceInjection extends MethodAnnotatedTurbineBaseServi log.info("localizationService is: " + localizationService); // setInit(true); } - - public void callService() + + public void callService() { assertNotNull("field injected localizationService object was Null.", localizationService); assertNotNull("method injected service serviceWithServiceInjection2 object was Null.", serviceWithServiceInjection2); diff --git a/src/test/org/apache/turbine/services/ServiceWithServiceInjection2.java b/src/test/org/apache/turbine/services/ServiceWithServiceInjection2.java index 1e5b96f9..e5ca3bbf 100644 --- a/src/test/org/apache/turbine/services/ServiceWithServiceInjection2.java +++ b/src/test/org/apache/turbine/services/ServiceWithServiceInjection2.java @@ -26,23 +26,23 @@ import org.apache.commons.logging.LogFactory; import org.apache.fulcrum.localization.LocalizationService; import org.apache.turbine.annotation.TurbineService; /** - * This service is used for testing 2nd level injection of services and class level declaration of - * {@link TurbineService} (interface is optional). + * This service is used for testing 2nd level injection of services and class level declaration of + * {@link TurbineService} (interface is optional). * * @author <a href="mailto:[email protected]">Georg Kallidis</a> */ @TurbineService( ServiceWithServiceInjection2.SERVICE_NAME ) -public class ServiceWithServiceInjection2 extends FieldAnnotatedTurbineBaseService +public class ServiceWithServiceInjection2 extends FieldAnnotatedTurbineBaseService { - + static final String SERVICE_NAME = "ServiceWithService2"; - + private static Log log = LogFactory.getLog(ServiceWithServiceInjection2.class); - + // Test for implicit SERVICE_NAME @TurbineService private LocalizationService localizationService2; - + /** * Initializes the service. */ @@ -53,8 +53,8 @@ public class ServiceWithServiceInjection2 extends FieldAnnotatedTurbineBaseServi log.info("localizationService2 is: " + localizationService2); // setInit(true); } - - public void callService() + + public void callService() { assertNotNull("localizationService2 object was Null.", localizationService2); } diff --git a/src/test/org/apache/turbine/services/localization/LocalizationToolTest.java b/src/test/org/apache/turbine/services/localization/LocalizationToolTest.java index dfb05786..7783c2b1 100644 --- a/src/test/org/apache/turbine/services/localization/LocalizationToolTest.java +++ b/src/test/org/apache/turbine/services/localization/LocalizationToolTest.java @@ -106,8 +106,7 @@ public class LocalizationToolTest extends BaseTestCase ServletConfig config = mock(ServletConfig.class); HttpServletRequest request = getMockRequest(); HttpServletResponse response = mock(HttpServletResponse.class); - RunData runData = rds.getRunData(request, response, config); - return runData; + return rds.getRunData(request, response, config); } @AfterClass diff --git a/src/test/org/apache/turbine/services/localization/RundataLocalizationToolTest.java b/src/test/org/apache/turbine/services/localization/RundataLocalizationToolTest.java index 9482674c..925c594c 100644 --- a/src/test/org/apache/turbine/services/localization/RundataLocalizationToolTest.java +++ b/src/test/org/apache/turbine/services/localization/RundataLocalizationToolTest.java @@ -56,22 +56,22 @@ import org.junit.jupiter.api.Test; public class RundataLocalizationToolTest extends BaseUnit5Test { private static TurbineConfig tc = null; - + @TurbineTool(LocalizationTool.class) private LocalizationTool lt; - + @BeforeAll public static void setUp() throws Exception { tc = new TurbineConfig(".", "/conf/test/rundataTemplateService.properties"); tc.initialize(); - + } @BeforeEach public void initTool() throws Exception { - AnnotationProcessor.process(this); + AnnotationProcessor.process(this); lt.init(getRunData()); } @@ -103,16 +103,16 @@ public class RundataLocalizationToolTest extends BaseUnit5Test HttpServletRequest request = getMockRequest(); HttpServletResponse response = mock(HttpServletResponse.class); RunData runData = rds.getRunData(request, response, config); - + User user = null; try { user = new DefaultUserImpl(mock(TurbineUser.class)); user.setTemp("locale", new Locale("de","DE") ); - runData.setUser(user); + runData.setUser(user); } catch (Exception e) { e.printStackTrace(); } - + return runData; } diff --git a/src/test/org/apache/turbine/services/urlmapper/TurbineURLMapperJSONServiceTest.java b/src/test/org/apache/turbine/services/urlmapper/TurbineURLMapperJSONServiceTest.java index 532719c9..966fff30 100644 --- a/src/test/org/apache/turbine/services/urlmapper/TurbineURLMapperJSONServiceTest.java +++ b/src/test/org/apache/turbine/services/urlmapper/TurbineURLMapperJSONServiceTest.java @@ -126,8 +126,8 @@ public class TurbineURLMapperJSONServiceTest extends BaseTestCase assertEquals( expectedMappedURL, uri2.getRelativeLink() ); pp.clear(); - -// + +// // scheme://bob/wow/damn2/contact/4/de log.info( "relative uri is now {}", uri2.getRelativeLink() ); urlMapper.mapFromURL( uri2.getRelativeLink(), pp ); @@ -148,7 +148,7 @@ public class TurbineURLMapperJSONServiceTest extends BaseTestCase assertEquals( expectedMappedURL, uri2.getRelativeLink() ); } - + @Test public void testIgnoreParameterForShortURL() throws Exception { @@ -188,7 +188,7 @@ public class TurbineURLMapperJSONServiceTest extends BaseTestCase assertEquals( expectedMappedURL, uri2.getRelativeLink() ); pp.clear(); - + uri2.addPathInfo( "de", "" ); // scheme://bob/wow/damn2/info/4/de/ log.info( "relative uri is now {}", uri2.getRelativeLink() ); diff --git a/src/test/org/apache/turbine/services/urlmapper/TurbineURLMapperServiceTest.java b/src/test/org/apache/turbine/services/urlmapper/TurbineURLMapperServiceTest.java index 24d01add..4c8eca38 100644 --- a/src/test/org/apache/turbine/services/urlmapper/TurbineURLMapperServiceTest.java +++ b/src/test/org/apache/turbine/services/urlmapper/TurbineURLMapperServiceTest.java @@ -197,10 +197,10 @@ public class TurbineURLMapperServiceTest extends BaseTestCase System.out.println("s1 estimateSize: " + spliterator1.estimateSize()); spliterator1.forEachRemaining((IntConsumer) i -> - runCheck(templateURIs, counterSum, counters, parallel, sr)); + runCheck(templateURIs, counterSum, counters, sr)); System.out.println("s2 estimateSize: " + spliterator2.estimateSize()); spliterator2.forEachRemaining((IntConsumer) i -> - runCheck(templateURIs, counterSum, counters, parallel, sr)); + runCheck(templateURIs, counterSum, counters, sr)); for (int i = 0; i < counters.size() - 1; i++) { @@ -220,8 +220,7 @@ public class TurbineURLMapperServiceTest extends BaseTestCase ); } - private void runCheck(int templateURIs, List<AtomicLong> counterSum, List<AtomicInteger> counters, boolean parallel, - SplittableRandom sr) + private void runCheck(int templateURIs, List<AtomicLong> counterSum, List<AtomicInteger> counters, SplittableRandom sr) { int randomNum = sr.nextInt(templateURIs); TemplateURI turi = getURI(randomNum); diff --git a/src/test/org/apache/turbine/test/BaseTestCase.java b/src/test/org/apache/turbine/test/BaseTestCase.java index 30fa41e1..c79addc0 100644 --- a/src/test/org/apache/turbine/test/BaseTestCase.java +++ b/src/test/org/apache/turbine/test/BaseTestCase.java @@ -69,13 +69,11 @@ public abstract class BaseTestCase RunDataService rds = (RunDataService) TurbineServices.getInstance().getService( RunDataService.SERVICE_NAME); - RunData runData = rds.getRunData(request, response, config); - return runData; + return rds.getRunData(request, response, config); } protected PipelineData getPipelineData(HttpServletRequest request,HttpServletResponse response,ServletConfig config) throws Exception { - RunData runData = getRunData(request,response,config); - return runData; + return getRunData(request,response,config); } protected Map<String,Object> attributes = new HashMap<>(); diff --git a/src/test/org/apache/turbine/testcontainer/BuildContainerWithDockerfileTest.java b/src/test/org/apache/turbine/testcontainer/BuildContainerWithDockerfileTest.java index 071f5c81..0d500f7c 100644 --- a/src/test/org/apache/turbine/testcontainer/BuildContainerWithDockerfileTest.java +++ b/src/test/org/apache/turbine/testcontainer/BuildContainerWithDockerfileTest.java @@ -131,7 +131,10 @@ class BuildContainerWithDockerfileTest { @Test @Order(2) void createUser() throws SQLException { - if (connection == null) return; + if (connection == null) + { + return; + } try (PreparedStatement preparedStatement = connection.prepareStatement( "INSERT INTO TURBINE_USER (USER_ID,LOGIN_NAME,PASSWORD_VALUE,FIRST_NAME,LAST_NAME) values (?,?,?,?,?)")) { @@ -148,7 +151,10 @@ class BuildContainerWithDockerfileTest { @Test @Order(1) void selectExistingUser() throws SQLException { - if (connection == null) return; + if (connection == null) + { + return; + } try (PreparedStatement preparedStatement = connection.prepareStatement( "select USER_ID, LAST_NAME, FIRST_NAME from TURBINE_USER where USER_ID=?")) { @@ -164,7 +170,10 @@ class BuildContainerWithDockerfileTest { @Test @Order(3) void selectNewUser() throws SQLException { - if (connection == null) return; + if (connection == null) + { + return; + } try (PreparedStatement preparedStatement = connection.prepareStatement( "select USER_ID, LAST_NAME, FIRST_NAME from TURBINE_USER where USER_ID=?")) { diff --git a/src/test/org/apache/turbine/testcontainer/UserManagerWithContainerTest.java b/src/test/org/apache/turbine/testcontainer/UserManagerWithContainerTest.java index a5ad159c..23117076 100644 --- a/src/test/org/apache/turbine/testcontainer/UserManagerWithContainerTest.java +++ b/src/test/org/apache/turbine/testcontainer/UserManagerWithContainerTest.java @@ -123,8 +123,8 @@ class UserManagerWithContainerTest { user.setAccessCounter( 5 ); user.setName( "ringo" ); // required not null constraint - ( (ExtendedUser) user ).setFirstName( user.getName() ); - ( (ExtendedUser) user ).setLastName( user.getName() ); + user.setFirstName( user.getName() ); + user.setLastName( user.getName() ); turbineSecurityService.addUser( user, "fakepassword" ); assertTrue( turbineSecurityService.accountExists( user ) ); //assertTrue( turbineSecurityService.getUserManager().checkExists( user ) ); diff --git a/src/test/org/apache/turbine/util/ObjectUtilsTest.java b/src/test/org/apache/turbine/util/ObjectUtilsTest.java index 4216d6b0..0cd62c6e 100644 --- a/src/test/org/apache/turbine/util/ObjectUtilsTest.java +++ b/src/test/org/apache/turbine/util/ObjectUtilsTest.java @@ -72,17 +72,17 @@ public class ObjectUtilsTest extends BaseTestCase throws Exception { Map<String, Object> map = new HashMap<>(); - map.put("testKey1", new HashBag<String>()); // forbidden class + map.put("testKey1", new HashBag<>()); // forbidden class map.put("testKey2", new Object()); // non-serializable map.put("testKey3", "actual Value"); assertEquals(map.size(), 3); - + final byte[] serialized1 = ObjectUtils.serializeMap(map); assertNotNull(serialized1); Map<String, Object> result1 = ObjectUtils.deserialize(serialized1); assertNull(result1); // Contains forbidden class - + map.remove("testKey1"); assertEquals(map.size(), 2); @@ -91,6 +91,6 @@ public class ObjectUtilsTest extends BaseTestCase Map<String, Object> result2 = ObjectUtils.deserialize(serialized2); assertNotNull(result2); // Does not contain forbidden class - assertEquals(result2.size(), 1); // Non-serializable value skipped + assertEquals(result2.size(), 1); // Non-serializable value skipped } }
