diff --git a/.gitignore b/.gitignore
index c71b4410aa..0ded2a2277 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,8 +14,6 @@ nbproject/private
framework/tests-results
framework/src/version
framework/src/play/version
-framework/src/play/version
-framework/src/play/version
framework/tests/test-application/db
framework/play-*.jar
framework/docs
@@ -33,7 +31,6 @@ eclipse
.project
id
framework/tests-tmp
-framework/docs
dist
modules/bespin/lib/bespin.jar
modules/ecss/lib/ecss.jar
@@ -42,7 +39,6 @@ resources/catalog.xml
resources/nbproject/private
modules/gae/lib/gae.jar
catalog.xml
-modules/gae/lib/gae.jar
play-*.jar
modules/gae/bin
modules/gwt/lib/play-gwt.jar
@@ -51,7 +47,6 @@ test-result
logs
db
*.pyc
-test-result
samples-and-tests/with-gwt/nbproject
samples-and-tests/jobboard/db
samples-and-tests/jobboard/tmp
@@ -133,11 +128,7 @@ atlassian-ide-plugin.xml
modules/*
build.classes
modules/crud/nbproject
-nbproject
-samples-and-tests/jobboard/attachments
samples-and-tests/jobboard/logs
-samples-and-tests/jobboard/test-result
-samples-and-tests/jobboard/tmp
samples-and-tests/validation/logs
samples-and-tests/zencontact/precompiled
!modules/docviewer
@@ -148,4 +139,3 @@ samples-and-tests/zencontact/precompiled
!modules/testrunner
!framework/src/play/db
!framework/test-src/play/db
-*~
diff --git a/framework/build.xml b/framework/build.xml
index 7a2a2315cd..38a1271559 100644
--- a/framework/build.xml
+++ b/framework/build.xml
@@ -233,7 +233,7 @@
-
+
diff --git a/framework/src/play/Invoker.java b/framework/src/play/Invoker.java
index 2c11ce19d3..3f2b91bc2b 100644
--- a/framework/src/play/Invoker.java
+++ b/framework/src/play/Invoker.java
@@ -413,10 +413,9 @@ public String getErrorDescription() {
static class WaitForTasksCompletion extends Thread {
static WaitForTasksCompletion instance;
- Map, Invocation> queue;
+ final Map, Invocation> queue = new ConcurrentHashMap<>();
public WaitForTasksCompletion() {
- queue = new ConcurrentHashMap<>();
setName("WaitForTasksCompletion");
setDaemon(true);
}
diff --git a/framework/src/play/Logger.java b/framework/src/play/Logger.java
index 6eedae5a4c..d2cb7ae1be 100644
--- a/framework/src/play/Logger.java
+++ b/framework/src/play/Logger.java
@@ -47,7 +47,7 @@ public class Logger {
/**
* When using java.util.logging.
*/
- public static java.util.logging.Logger juli = java.util.logging.Logger.getLogger("play");
+ public static final java.util.logging.Logger juli = java.util.logging.Logger.getLogger("play");
/**
* true if logger is configured manually (log4j-config file supplied by application)
*/
diff --git a/framework/src/play/Play.java b/framework/src/play/Play.java
index 4e4a88c83c..1241fdac71 100644
--- a/framework/src/play/Play.java
+++ b/framework/src/play/Play.java
@@ -115,7 +115,7 @@ public boolean isProd() {
/**
* All paths to search for files
*/
- public static List roots = new ArrayList<>(16);
+ public static final List roots = new ArrayList<>(16);
/**
* All paths to search for Java files
*/
@@ -123,7 +123,7 @@ public boolean isProd() {
/**
* All paths to search for templates files
*/
- public static List templatesPath = new ArrayList<>(2);
+ public static final List templatesPath = new ArrayList<>(2);
/**
* Main routes file
*/
@@ -131,7 +131,7 @@ public boolean isProd() {
/**
* Plugin routes files
*/
- public static Map modulesRoutes = new HashMap<>(16);
+ public static final Map modulesRoutes = new HashMap<>(16);
/**
* The loaded configuration files
*/
@@ -166,7 +166,7 @@ public boolean isProd() {
/**
* Modules
*/
- public static Map modules = new HashMap<>(16);
+ public static final Map modules = new HashMap<>(16);
/**
* Framework version
*/
@@ -426,7 +426,7 @@ private static Properties readOneConfigurationFile(String filename) {
for (Object key : propsFromFile.keySet()) {
String value = propsFromFile.getProperty(key.toString());
Matcher matcher = pattern.matcher(value);
- StringBuffer newValue = new StringBuffer(100);
+ StringBuilder newValue = new StringBuilder(100);
while (matcher.find()) {
String jp = matcher.group(1);
String r;
diff --git a/framework/src/play/PlayPlugin.java b/framework/src/play/PlayPlugin.java
index 543bbf802c..d5337bba8e 100644
--- a/framework/src/play/PlayPlugin.java
+++ b/framework/src/play/PlayPlugin.java
@@ -514,7 +514,7 @@ public Collection getFunctionalTests() {
* transaction around an action. The filter applies a transaction to the current Action.
*/
public abstract static class Filter {
- String name;
+ final String name;
public Filter(String name) {
this.name = name;
diff --git a/framework/src/play/cache/EhCacheImpl.java b/framework/src/play/cache/EhCacheImpl.java
index a8f604620d..3b08410737 100644
--- a/framework/src/play/cache/EhCacheImpl.java
+++ b/framework/src/play/cache/EhCacheImpl.java
@@ -20,16 +20,15 @@
*/
public class EhCacheImpl implements CacheImpl {
+ private static final String cacheName = "play";
private static EhCacheImpl uniqueInstance;
- CacheManager cacheManager;
+ final CacheManager cacheManager = CacheManager.create();
- net.sf.ehcache.Cache cache;
+ final net.sf.ehcache.Cache cache;
- private static final String cacheName = "play";
private EhCacheImpl() {
- this.cacheManager = CacheManager.create();
this.cacheManager.addCache(cacheName);
this.cache = cacheManager.getCache(cacheName);
}
diff --git a/framework/src/play/classloading/ApplicationClasses.java b/framework/src/play/classloading/ApplicationClasses.java
index a832515d02..9e7eec9d5a 100644
--- a/framework/src/play/classloading/ApplicationClasses.java
+++ b/framework/src/play/classloading/ApplicationClasses.java
@@ -26,7 +26,7 @@ public class ApplicationClasses {
/**
* Reference to the eclipse compiler.
*/
- ApplicationCompiler compiler = new ApplicationCompiler(this);
+ final ApplicationCompiler compiler = new ApplicationCompiler(this);
/**
* Cache of all compiled classes
*/
diff --git a/framework/src/play/classloading/ApplicationClassloader.java b/framework/src/play/classloading/ApplicationClassloader.java
index 279c63a4c7..edcfe86e8d 100644
--- a/framework/src/play/classloading/ApplicationClassloader.java
+++ b/framework/src/play/classloading/ApplicationClassloader.java
@@ -323,8 +323,7 @@ public void detectChanges() throws RestartNeededException {
modifieds.add(applicationClass);
}
}
- Set modifiedWithDependencies = new HashSet<>();
- modifiedWithDependencies.addAll(modifieds);
+ Set modifiedWithDependencies = new HashSet<>(modifieds);
if (!modifieds.isEmpty()) {
modifiedWithDependencies.addAll(Play.pluginCollection.onClassesChange(modifieds));
}
@@ -446,7 +445,7 @@ public List getAllClasses() {
}
}
- Collections.sort(result, Comparator.comparing(Class::getName));
+ result.sort(Comparator.comparing(Class::getName));
}
Map byNormalizedName = new HashMap<>(result.size());
diff --git a/framework/src/play/classloading/ApplicationClassloaderState.java b/framework/src/play/classloading/ApplicationClassloaderState.java
index 20bbc73191..725ea9d7a7 100644
--- a/framework/src/play/classloading/ApplicationClassloaderState.java
+++ b/framework/src/play/classloading/ApplicationClassloaderState.java
@@ -13,7 +13,7 @@
* they could check if the state of the ApplicationClassloader has changed..
*/
public class ApplicationClassloaderState {
- private static AtomicLong nextStateValue = new AtomicLong();
+ private static final AtomicLong nextStateValue = new AtomicLong();
private final long currentStateValue = nextStateValue.getAndIncrement();
@@ -24,9 +24,7 @@ public boolean equals(Object o) {
ApplicationClassloaderState that = (ApplicationClassloaderState) o;
- if (currentStateValue != that.currentStateValue) return false;
-
- return true;
+ return this.currentStateValue == that.currentStateValue;
}
@Override
diff --git a/framework/src/play/classloading/ApplicationCompiler.java b/framework/src/play/classloading/ApplicationCompiler.java
index 11f6250eb6..f0ce32ef34 100644
--- a/framework/src/play/classloading/ApplicationCompiler.java
+++ b/framework/src/play/classloading/ApplicationCompiler.java
@@ -34,21 +34,21 @@
*/
public class ApplicationCompiler {
- Map packagesCache = new HashMap<>();
- ApplicationClasses applicationClasses;
- Map settings;
private static final String JAVA_SOURCE_DEFAULT_VERSION = "11";
- static final Map compatibleJavaVersions = new HashMap<>();
- static {
- compatibleJavaVersions.put("11", CompilerOptions.VERSION_11);
- compatibleJavaVersions.put("12", CompilerOptions.VERSION_12);
- compatibleJavaVersions.put("13", CompilerOptions.VERSION_13);
- compatibleJavaVersions.put("14", CompilerOptions.VERSION_14);
- compatibleJavaVersions.put("15", CompilerOptions.VERSION_15);
- compatibleJavaVersions.put("16", CompilerOptions.VERSION_16);
- compatibleJavaVersions.put("17", CompilerOptions.VERSION_17);
- compatibleJavaVersions.put("18", CompilerOptions.VERSION_18);
- }
+ static final Map compatibleJavaVersions = Map.of(
+ "11", CompilerOptions.VERSION_11,
+ "12", CompilerOptions.VERSION_12,
+ "13", CompilerOptions.VERSION_13,
+ "14", CompilerOptions.VERSION_14,
+ "15", CompilerOptions.VERSION_15,
+ "16", CompilerOptions.VERSION_16,
+ "17", CompilerOptions.VERSION_17,
+ "18", CompilerOptions.VERSION_18
+ );
+
+ final Map packagesCache = new HashMap<>();
+ final ApplicationClasses applicationClasses;
+ final Map settings;
/**
* Try to guess the magic configuration options
@@ -57,32 +57,33 @@ public class ApplicationCompiler {
* The application classes container
*/
public ApplicationCompiler(ApplicationClasses applicationClasses) {
- this.applicationClasses = applicationClasses;
- this.settings = new HashMap<>();
- this.settings.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.IGNORE);
- this.settings.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
- this.settings.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE);
- this.settings.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE);
- this.settings.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE);
- this.settings.put(CompilerOptions.OPTION_Encoding, "UTF-8");
- this.settings.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);
-
final String runningJavaVersion = System.getProperty("java.version");
- if (Stream.of("1.5", "1.6", "1.7", "1.8", "9", "10").anyMatch(runningJavaVersion::startsWith)) {
+ if (Stream.of("1.5", "1.6", "1.7", "1.8", "9", "10").anyMatch(runningJavaVersion::startsWith)) {
throw new CompilationException("JDK version prior to 11 are not supported to run the application");
}
+
final String configSourceVersion = Play.configuration.getProperty("java.source", JAVA_SOURCE_DEFAULT_VERSION);
final String jdtVersion = compatibleJavaVersions.get(configSourceVersion);
if (jdtVersion == null) {
throw new CompilationException(String.format("Incompatible Java version specified (%s). Compatible versions are: %s",
- configSourceVersion, compatibleJavaVersions.keySet()));
+ configSourceVersion, compatibleJavaVersions.keySet()));
}
- this.settings.put(CompilerOptions.OPTION_Source, jdtVersion);
- this.settings.put(CompilerOptions.OPTION_TargetPlatform, jdtVersion);
- this.settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE);
- this.settings.put(CompilerOptions.OPTION_Compliance, jdtVersion);
- this.settings.put(CompilerOptions.OPTION_MethodParametersAttribute, CompilerOptions.GENERATE);
+ this.applicationClasses = applicationClasses;
+ this.settings = Map.ofEntries(
+ Map.entry(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.IGNORE),
+ Map.entry(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE),
+ Map.entry(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE),
+ Map.entry(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE),
+ Map.entry(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE),
+ Map.entry(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE),
+ Map.entry(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE),
+ Map.entry(CompilerOptions.OPTION_MethodParametersAttribute, CompilerOptions.GENERATE),
+ Map.entry(CompilerOptions.OPTION_Encoding, "UTF-8"),
+ Map.entry(CompilerOptions.OPTION_Source, jdtVersion),
+ Map.entry(CompilerOptions.OPTION_TargetPlatform, jdtVersion),
+ Map.entry(CompilerOptions.OPTION_Compliance, jdtVersion)
+ );
}
/**
diff --git a/framework/src/play/classloading/enhancers/ContinuationEnhancer.java b/framework/src/play/classloading/enhancers/ContinuationEnhancer.java
index 0340b5faaa..456f28704e 100644
--- a/framework/src/play/classloading/enhancers/ContinuationEnhancer.java
+++ b/framework/src/play/classloading/enhancers/ContinuationEnhancer.java
@@ -15,16 +15,14 @@
public class ContinuationEnhancer extends Enhancer {
- static final List continuationMethods = new ArrayList<>();
-
- static {
- continuationMethods.add("play.mvc.Controller.await(java.lang.String)");
- continuationMethods.add("play.mvc.Controller.await(int)");
- continuationMethods.add("play.mvc.Controller.await(java.util.concurrent.Future)");
- continuationMethods.add("play.mvc.WebSocketController.await(java.lang.String)");
- continuationMethods.add("play.mvc.WebSocketController.await(int)");
- continuationMethods.add("play.mvc.WebSocketController.await(java.util.concurrent.Future)");
- }
+ private static final List continuationMethods = List.of(
+ "play.mvc.Controller.await(java.lang.String)",
+ "play.mvc.Controller.await(int)",
+ "play.mvc.Controller.await(java.util.concurrent.Future)",
+ "play.mvc.WebSocketController.await(java.lang.String)",
+ "play.mvc.WebSocketController.await(int)",
+ "play.mvc.WebSocketController.await(java.util.concurrent.Future)"
+ );
public static boolean isEnhanced(String appClassName) {
ApplicationClass appClass = Play.classes.getApplicationClass( appClassName);
diff --git a/framework/src/play/classloading/enhancers/Enhancer.java b/framework/src/play/classloading/enhancers/Enhancer.java
index 5203f07d2d..04743fb644 100644
--- a/framework/src/play/classloading/enhancers/Enhancer.java
+++ b/framework/src/play/classloading/enhancers/Enhancer.java
@@ -29,7 +29,7 @@
*/
public abstract class Enhancer {
- protected ClassPool classPool;
+ protected final ClassPool classPool;
public Enhancer() {
this.classPool = newClassPool();
diff --git a/framework/src/play/classloading/enhancers/LocalvariablesNamesEnhancer.java b/framework/src/play/classloading/enhancers/LocalvariablesNamesEnhancer.java
index fc41da7ab1..17a26e408e 100644
--- a/framework/src/play/classloading/enhancers/LocalvariablesNamesEnhancer.java
+++ b/framework/src/play/classloading/enhancers/LocalvariablesNamesEnhancer.java
@@ -181,9 +181,7 @@ public static void checkEmpty() {
}
public static void clear() {
- if (localVariables.get() != null) {
- localVariables.set(null);
- }
+ localVariables.remove();
}
public static void enter() {
@@ -280,43 +278,41 @@ public static void setLocalVariablesStateAfterAwait(Stack
*/
- public static Pattern oldCookieSessionParser = Pattern.compile("\u0000([^:]*):([^\u0000]*)\u0000");
+ public static final Pattern oldCookieSessionParser = Pattern.compile("\u0000([^:]*):([^\u0000]*)\u0000");
/**
* @param map
diff --git a/framework/src/play/mvc/Http.java b/framework/src/play/mvc/Http.java
index a1a02f0c25..5ec27af3b0 100644
--- a/framework/src/play/mvc/Http.java
+++ b/framework/src/play/mvc/Http.java
@@ -268,7 +268,7 @@ public static class Request implements Serializable {
/**
* Free space to store your request specific data
*/
- public Map args = new HashMap<>(16);
+ public final Map args = new HashMap<>(16);
/**
* When the request has been received
*/
@@ -576,7 +576,7 @@ public List acceptLanguage() {
}
String acceptLanguage = headers.get("accept-language").value();
List languages = Arrays.asList(acceptLanguage.split(","));
- Collections.sort(languages, (lang1, lang2) -> {
+ languages.sort((lang1, lang2) -> {
double q1 = 1.0;
double q2 = 1.0;
Matcher m1 = qpattern.matcher(lang1);
@@ -621,11 +621,11 @@ public static class Response {
/**
* Response headers
*/
- public Map headers = new HashMap<>(16);
+ public final Map headers = new HashMap<>(16);
/**
* Response cookies
*/
- public Map cookies = new HashMap<>(16);
+ public final Map cookies = new HashMap<>(16);
/**
* Response body stream
*/
diff --git a/framework/src/play/mvc/Router.java b/framework/src/play/mvc/Router.java
index dea0a61e8c..8c81936faa 100644
--- a/framework/src/play/mvc/Router.java
+++ b/framework/src/play/mvc/Router.java
@@ -28,12 +28,12 @@
*/
public class Router {
- static Pattern routePattern = new Pattern(
+ static final Pattern routePattern = new Pattern(
"^({method}GET|POST|PUT|PATCH|DELETE|OPTIONS|HEAD|WS|\\*)[(]?({headers}[^)]*)(\\))?\\s+({path}.*/[^\\s]*)\\s+({action}[^\\s(]+)({params}.+)?(\\s*)$");
/**
* Pattern used to locate a method override instruction in request.querystring
*/
- static Pattern methodOverride = new Pattern("^.*x-http-method-override=({method}GET|PUT|POST|PATCH|DELETE).*$");
+ static final Pattern methodOverride = new Pattern("^.*x-http-method-override=({method}GET|PUT|POST|PATCH|DELETE).*$");
/**
* Timestamp the routes file was last loaded at.
*/
@@ -341,7 +341,7 @@ public static void detectChanges(String prefix) {
/**
* All the loaded routes.
*/
- public static List routes = new CopyOnWriteArrayList<>();
+ public static final List routes = new CopyOnWriteArrayList<>();
public static void routeOnlyStatic(Http.Request request) {
for (Route route : routes) {
@@ -714,8 +714,8 @@ private static List findActionRoutes(String action) {
}
private static final class ActionRoute {
+ private final Map args = new HashMap<>(2);
private Route route;
- private Map args = new HashMap<>(2);
}
public static class ActionDefinition {
@@ -828,9 +828,9 @@ public static class Route {
Arg hostArg = null;
public int routesFileLine;
public String routesFile;
- static Pattern customRegexPattern = new Pattern("\\{([a-zA-Z_][a-zA-Z_0-9]*)\\}");
- static Pattern argsPattern = new Pattern("\\{<([^>]+)>([a-zA-Z_0-9]+)\\}");
- static Pattern paramPattern = new Pattern("([a-zA-Z_0-9]+):'(.*)'");
+ static final Pattern customRegexPattern = new Pattern("\\{([a-zA-Z_][a-zA-Z_0-9]*)\\}");
+ static final Pattern argsPattern = new Pattern("\\{<([^>]+)>([a-zA-Z_0-9]+)\\}");
+ static final Pattern paramPattern = new Pattern("([a-zA-Z_0-9]+):'(.*)'");
public void compute() {
this.host = "";
diff --git a/framework/src/play/mvc/Scope.java b/framework/src/play/mvc/Scope.java
index b7c53908d0..4e58f6c3b7 100644
--- a/framework/src/play/mvc/Scope.java
+++ b/framework/src/play/mvc/Scope.java
@@ -33,7 +33,7 @@ public class Scope {
public static boolean SESSION_SEND_ONLY_IF_CHANGED = Play.configuration
.getProperty("application.session.sendOnlyIfChanged", "false").toLowerCase().equals("true");
- public static SessionStore sessionStore = createSessionStore();
+ public static final SessionStore sessionStore = createSessionStore();
private static SessionStore createSessionStore() {
String sessionStoreClass = Play.configuration.getProperty("application.session.storeClass");
@@ -55,8 +55,8 @@ private static SessionStore createSessionStore() {
*/
public static class Flash {
- Map data = new HashMap<>();
- Map out = new HashMap<>();
+ final Map data = new HashMap<>();
+ final Map out = new HashMap<>();
public static Flash restore() {
try {
@@ -179,7 +179,7 @@ public static Session restore() {
return sessionStore.restore();
}
- Map data = new HashMap<>(); // ThreadLocal access
+ final Map data = new HashMap<>(); // ThreadLocal access
boolean changed = false;
public static final ThreadLocal current = new ThreadLocal<>();
@@ -292,7 +292,7 @@ public static Params current() {
}
boolean requestIsParsed;
- public Map data = new LinkedHashMap<>();
+ public final Map data = new LinkedHashMap<>();
boolean rootParamsNodeIsGenerated = false;
private RootParamNode rootParamNode = null;
@@ -356,13 +356,7 @@ public void remove(String key) {
public void removeStartWith(String prefix) {
checkAndParse();
- Iterator> iterator = data.entrySet().iterator();
- while (iterator.hasNext()) {
- Map.Entry entry = iterator.next();
- if (entry.getKey().startsWith(prefix)) {
- iterator.remove();
- }
- }
+ data.entrySet().removeIf(entry -> entry.getKey().startsWith(prefix));
// make sure rootsParamsNode is regenerated if needed
rootParamsNodeIsGenerated = false;
}
@@ -519,7 +513,7 @@ public String toString() {
*/
public static class RenderArgs {
- public Map data = new HashMap<>(); // ThreadLocal access
+ public final Map data = new HashMap<>(); // ThreadLocal access
public static final ThreadLocal current = new ThreadLocal<>();
public static RenderArgs current() {
@@ -550,7 +544,7 @@ public String toString() {
*/
public static class RouteArgs {
- public Map data = new HashMap<>(); // ThreadLocal access
+ public final Map data = new HashMap<>(); // ThreadLocal access
public static final ThreadLocal current = new ThreadLocal<>();
public static RouteArgs current() {
diff --git a/framework/src/play/mvc/results/RenderBinary.java b/framework/src/play/mvc/results/RenderBinary.java
index 559c3e504d..91d78b0e97 100644
--- a/framework/src/play/mvc/results/RenderBinary.java
+++ b/framework/src/play/mvc/results/RenderBinary.java
@@ -9,6 +9,7 @@
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
+import java.nio.charset.StandardCharsets;
import org.apache.commons.codec.net.URLCodec;
import org.apache.commons.io.IOUtils;
@@ -211,7 +212,7 @@ private static void copyInputStreamAndClose(InputStream is, OutputStream out) th
}
private boolean canAsciiEncode(String string) {
- CharsetEncoder asciiEncoder = Charset.forName("US-ASCII").newEncoder();
+ CharsetEncoder asciiEncoder = StandardCharsets.US_ASCII.newEncoder();
return asciiEncoder.canEncode(string);
}
diff --git a/framework/src/play/mvc/results/RenderJson.java b/framework/src/play/mvc/results/RenderJson.java
index 57f8f4fccd..a0a92889fc 100644
--- a/framework/src/play/mvc/results/RenderJson.java
+++ b/framework/src/play/mvc/results/RenderJson.java
@@ -5,6 +5,7 @@
import com.google.gson.JsonSerializer;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
+import java.util.Objects;
import play.exceptions.UnexpectedException;
import play.mvc.Http.Request;
@@ -47,11 +48,7 @@ public RenderJson(String jsonString) {
public RenderJson(Object response, Gson gson) {
this.response = response;
- if (gson != null) {
- json = gson.toJson(response);
- } else {
- json = GSON.toJson(response);
- }
+ json = Objects.requireNonNullElse(gson, GSON).toJson(response);
}
@Override
diff --git a/framework/src/play/plugins/PluginCollection.java b/framework/src/play/plugins/PluginCollection.java
index 1cefe15153..c5cd8ee885 100644
--- a/framework/src/play/plugins/PluginCollection.java
+++ b/framework/src/play/plugins/PluginCollection.java
@@ -56,7 +56,7 @@ public class PluginCollection {
/**
* List that holds all loaded plugins, enabled or disabled
*/
- protected List allPlugins = new ArrayList<>();
+ protected final List allPlugins = new ArrayList<>();
/**
* Readonly copy of allPlugins - updated each time allPlugins is updated. Using this cached copy so we don't have to
@@ -67,7 +67,7 @@ public class PluginCollection {
/**
* List of all enabled plugins
*/
- protected List enabledPlugins = new ArrayList<>();
+ protected final List enabledPlugins = new ArrayList<>();
/**
* Readonly copy of enabledPlugins - updated each time enabledPlugins is updated. Using this cached copy so we don't
@@ -78,7 +78,7 @@ public class PluginCollection {
/**
* List of all enabled plugins with filters
*/
- protected List enabledPluginsWithFilters = new ArrayList<>();
+ protected final List enabledPluginsWithFilters = new ArrayList<>();
/**
* Readonly copy of enabledPluginsWithFilters - updated each time enabledPluginsWithFilters is updated. Using this
@@ -94,7 +94,7 @@ public class PluginCollection {
* @return Read only list of plugins
*/
protected List createReadonlyCopy(List list) {
- return Collections.unmodifiableList(new ArrayList<>(list));
+ return List.copyOf(list);
}
private static class LoadingPluginInfo implements Comparable {
@@ -202,7 +202,7 @@ List loadPlayPluginDescriptors() {
String playPluginsDescriptors = Play.configuration.getProperty("play.plugins.descriptor");
if (playPluginsDescriptors != null) {
return Stream.of(playPluginsDescriptors.split(","))
- .map(playPluginsDescriptor -> fileToUrl(playPluginsDescriptor))
+ .map(this::fileToUrl)
.collect(toList());
}
return Collections.list(Play.classloader.getResources(play_plugins_resourceName));
diff --git a/framework/src/play/server/FileService.java b/framework/src/play/server/FileService.java
index 1213e9ebb1..9b94575527 100644
--- a/framework/src/play/server/FileService.java
+++ b/framework/src/play/server/FileService.java
@@ -273,9 +273,9 @@ private static String makeRangeBodyHeader(String separator, String contentType,
}
private class ByteRange {
- public long start;
- public long end;
- public byte[] header;
+ public final long start;
+ public final long end;
+ public final byte[] header;
public long length() {
return end - start + 1;
diff --git a/framework/src/play/server/HttpServerPipelineFactory.java b/framework/src/play/server/HttpServerPipelineFactory.java
index 4dac6212cb..ca006c307c 100644
--- a/framework/src/play/server/HttpServerPipelineFactory.java
+++ b/framework/src/play/server/HttpServerPipelineFactory.java
@@ -5,6 +5,8 @@
import org.jboss.netty.channel.ChannelHandler;
import play.Play;
import play.Logger;
+import play.exceptions.UnexpectedException;
+
import java.util.Map;
import java.util.HashMap;
@@ -12,9 +14,9 @@
public class HttpServerPipelineFactory implements ChannelPipelineFactory {
- private String pipelineConfig = Play.configuration.getProperty("play.netty.pipeline", "play.server.FlashPolicyHandler,org.jboss.netty.handler.codec.http.HttpRequestDecoder,play.server.StreamChunkAggregator,org.jboss.netty.handler.codec.http.HttpResponseEncoder,org.jboss.netty.handler.stream.ChunkedWriteHandler,play.server.PlayHandler");
+ protected static final Map classes = new HashMap<>();
- protected static Map classes = new HashMap<>();
+ private final String pipelineConfig = Play.configuration.getProperty("play.netty.pipeline", "play.server.FlashPolicyHandler,org.jboss.netty.handler.codec.http.HttpRequestDecoder,play.server.StreamChunkAggregator,org.jboss.netty.handler.codec.http.HttpResponseEncoder,org.jboss.netty.handler.stream.ChunkedWriteHandler,play.server.PlayHandler");
@Override
public ChannelPipeline getPipeline() throws Exception {
@@ -51,11 +53,9 @@ public ChannelPipeline getPipeline() throws Exception {
}
}
- if (playHandler != null) {
- pipeline.addLast("handler", playHandler);
- playHandler.pipelines.put("handler", playHandler);
- }
-
+ pipeline.addLast("handler", playHandler);
+ playHandler.pipelines.put("handler", playHandler);
+
return pipeline;
}
@@ -68,11 +68,13 @@ protected String getName(String name) {
protected ChannelHandler getInstance(String name) throws Exception {
- Class clazz = classes.get(name);
- if (clazz == null) {
- clazz = Class.forName(name);
- classes.put(name, clazz);
- }
+ Class clazz = classes.computeIfAbsent(name, className -> {
+ try {
+ return Class.forName(className);
+ } catch (ClassNotFoundException e) {
+ throw new UnexpectedException(e);
+ }
+ });
if (ChannelHandler.class.isAssignableFrom(clazz))
return (ChannelHandler)clazz.newInstance();
return null;
diff --git a/framework/src/play/server/PlayHandler.java b/framework/src/play/server/PlayHandler.java
index c2474e19d8..5a1291e0b8 100644
--- a/framework/src/play/server/PlayHandler.java
+++ b/framework/src/play/server/PlayHandler.java
@@ -40,10 +40,7 @@
import java.io.*;
import java.net.InetSocketAddress;
import java.net.URLEncoder;
-import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@@ -69,14 +66,10 @@ public class PlayHandler extends SimpleChannelUpstreamHandler {
private static final String signature = "Play! Framework;" + Play.version + ";" + Play.mode.name().toLowerCase();
private static final boolean exposePlayServer;
- private static final String ACCEPT_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
- private static final Charset ASCII = Charset.forName("ASCII");
- private static final MessageDigest SHA_1;
-
/**
* The Pipeline is given for a PlayHandler
*/
- public Map pipelines = new HashMap<>();
+ public final Map pipelines = new HashMap<>();
private WebSocketServerHandshaker handshaker;
@@ -87,14 +80,6 @@ public class PlayHandler extends SimpleChannelUpstreamHandler {
*/
private static final Set allowedHttpMethodOverride;
- static {
- try {
- SHA_1 = MessageDigest.getInstance("SHA1");
- } catch (NoSuchAlgorithmException e) {
- throw new IllegalStateException("SHA-1 not supported on this platform", e);
- }
- }
-
static {
exposePlayServer = !"false".equals(Play.configuration.getProperty("http.exposePlayServer"));
allowedHttpMethodOverride = Stream.of(Play.configuration.getProperty("http.allowed.method.override", "").split(",")).collect(Collectors.toSet());
@@ -197,10 +182,10 @@ public boolean init() {
Response.current.set(response);
Scope.Params.current.set(request.params);
- Scope.RenderArgs.current.set(null);
- Scope.RouteArgs.current.set(null);
- Scope.Session.current.set(null);
- Scope.Flash.current.set(null);
+ Scope.RenderArgs.current.remove();
+ Scope.RouteArgs.current.remove();
+ Scope.Session.current.remove();
+ Scope.Flash.current.remove();
CachedBoundActionMethodArgs.init();
try {
@@ -647,10 +632,7 @@ protected static Map getHeaders(HttpRequest nettyRequest) {
for (String key : nettyRequest.headers().names()) {
Http.Header hd = new Http.Header();
hd.name = key.toLowerCase();
- hd.values = new ArrayList<>();
- for (String next : nettyRequest.headers().getAll(key)) {
- hd.values.add(next);
- }
+ hd.values = new ArrayList<>(nettyRequest.headers().getAll(key));
headers.put(hd.name, hd);
}
@@ -965,8 +947,8 @@ public static void setContentLength(HttpMessage message, long contentLength) {
static class LazyChunkedInput implements org.jboss.netty.handler.stream.ChunkedInput {
+ private final ConcurrentLinkedQueue nextChunks = new ConcurrentLinkedQueue<>();
private boolean closed = false;
- private ConcurrentLinkedQueue nextChunks = new ConcurrentLinkedQueue<>();
@Override
public boolean hasNextChunk() throws Exception {
diff --git a/framework/src/play/server/ServletWrapper.java b/framework/src/play/server/ServletWrapper.java
index 9a95315481..83bc9028f8 100644
--- a/framework/src/play/server/ServletWrapper.java
+++ b/framework/src/play/server/ServletWrapper.java
@@ -510,10 +510,10 @@ private void copyStream(HttpServletResponse servletResponse, InputStream is) thr
public class ServletInvocation extends Invoker.DirectInvocation {
- private Request request;
- private Response response;
- private HttpServletRequest httpServletRequest;
- private HttpServletResponse httpServletResponse;
+ private final Request request;
+ private final Response response;
+ private final HttpServletRequest httpServletRequest;
+ private final HttpServletResponse httpServletResponse;
public ServletInvocation(Request request, Response response, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
this.httpServletRequest = httpServletRequest;
diff --git a/framework/src/play/server/ssl/SslHttpServerContextFactory.java b/framework/src/play/server/ssl/SslHttpServerContextFactory.java
index b4da404886..9146bd26c7 100644
--- a/framework/src/play/server/ssl/SslHttpServerContextFactory.java
+++ b/framework/src/play/server/ssl/SslHttpServerContextFactory.java
@@ -80,7 +80,7 @@ public static SSLContext getServerContext() {
public static class PEMKeyManager extends X509ExtendedKeyManager {
- static PEMKeyManager instance = new PEMKeyManager();
+ static final PEMKeyManager instance = new PEMKeyManager();
PrivateKey key;
X509Certificate[] chain;
diff --git a/framework/src/play/server/ssl/SslHttpServerPipelineFactory.java b/framework/src/play/server/ssl/SslHttpServerPipelineFactory.java
index 295d6643e0..f622a9295c 100644
--- a/framework/src/play/server/ssl/SslHttpServerPipelineFactory.java
+++ b/framework/src/play/server/ssl/SslHttpServerPipelineFactory.java
@@ -14,7 +14,7 @@
public class SslHttpServerPipelineFactory extends HttpServerPipelineFactory {
- private String pipelineConfig = Play.configuration.getProperty("play.ssl.netty.pipeline",
+ private final String pipelineConfig = Play.configuration.getProperty("play.ssl.netty.pipeline",
"play.server.FlashPolicyHandler,org.jboss.netty.handler.codec.http.HttpRequestDecoder,play.server.StreamChunkAggregator,org.jboss.netty.handler.codec.http.HttpResponseEncoder,org.jboss.netty.handler.stream.ChunkedWriteHandler,play.server.ssl.SslPlayHandler");
@Override
diff --git a/framework/src/play/templates/BaseTemplate.java b/framework/src/play/templates/BaseTemplate.java
index dae9a543c0..7b3e4fd0e0 100644
--- a/framework/src/play/templates/BaseTemplate.java
+++ b/framework/src/play/templates/BaseTemplate.java
@@ -18,12 +18,12 @@
public abstract class BaseTemplate extends Template {
+ public final Long timestamp = System.currentTimeMillis();
public String compiledSource;
public Map linesMatrix = new HashMap<>();
public Set doBodyLines = new HashSet<>();
public Class compiledTemplate;
public String compiledTemplateName;
- public Long timestamp = System.currentTimeMillis();
public BaseTemplate(String name, String source) {
this.name = name;
@@ -97,7 +97,7 @@ void throwException(Throwable e) {
public static final class RawData {
- public String data;
+ public final String data;
public RawData(Object val) {
if (val == null) {
diff --git a/framework/src/play/templates/FastTags.java b/framework/src/play/templates/FastTags.java
index ebc5448302..70ae069da2 100644
--- a/framework/src/play/templates/FastTags.java
+++ b/framework/src/play/templates/FastTags.java
@@ -414,8 +414,7 @@ public static void _include(Map, ?> args, Closure body, PrintWriter out, Execu
name = ct + name.substring(1);
}
BaseTemplate t = (BaseTemplate) TemplateLoader.load(name);
- Map newArgs = new HashMap<>();
- newArgs.putAll(template.getBinding().getVariables());
+ Map newArgs = new HashMap<>(template.getBinding().getVariables());
newArgs.put("_isInclude", true);
t.internalRender(newArgs);
} catch (TemplateNotFoundException e) {
@@ -441,8 +440,7 @@ public static void _render(Map, ?> args, Closure body, PrintWriter out, Execut
}
args.remove("arg");
BaseTemplate t = (BaseTemplate) TemplateLoader.load(name);
- Map newArgs = new HashMap<>();
- newArgs.putAll((Map extends String, ? extends Object>) args);
+ Map newArgs = new HashMap<>((Map extends String, ? extends Object>) args);
newArgs.put("_isInclude", true);
newArgs.put("out", out);
t.internalRender(newArgs);
diff --git a/framework/src/play/templates/GroovyTemplate.java b/framework/src/play/templates/GroovyTemplate.java
index fb0a71cbf5..73ea940110 100644
--- a/framework/src/play/templates/GroovyTemplate.java
+++ b/framework/src/play/templates/GroovyTemplate.java
@@ -156,12 +156,7 @@ public void compile() {
Collection[] phases = (Collection[]) phasesF.get(compilationUnit);
LinkedList output = new LinkedList<>();
phases[Phases.OUTPUT] = output;
- output.add(new IGroovyClassOperation() {
- @Override
- public void call(GroovyClass gclass) {
- groovyClassesForThisTemplate.add(gclass);
- }
- });
+ output.add(groovyClassesForThisTemplate::add);
compilationUnit.compile();
// ouf
@@ -277,7 +272,7 @@ protected String internalRender(Map args) {
// We have to set up the PrintWriter that this (and all sub-templates) are going
// to write the output to..
applyLayouts = true;
- layout.set(null);
+ layout.remove();
writer = new StringWriter();
binding.setProperty("out", new PrintWriter(writer));
currentTemplate.set(this);
diff --git a/framework/src/play/templates/GroovyTemplateCompiler.java b/framework/src/play/templates/GroovyTemplateCompiler.java
index 41e9234beb..78bfdb9d17 100644
--- a/framework/src/play/templates/GroovyTemplateCompiler.java
+++ b/framework/src/play/templates/GroovyTemplateCompiler.java
@@ -17,7 +17,7 @@
public class GroovyTemplateCompiler extends TemplateCompiler {
- protected List extensionsClassnames = new ArrayList<>();
+ protected final List extensionsClassnames = new ArrayList<>();
// [#714] The groovy-compiler complaints if a line is more than 65535 unicode units long..
// Have to split it if it is really that big
@@ -79,7 +79,7 @@ protected String checkScalaCompatibility(String source) {
originalNames.put(name, clazz.getName());
}
}
- Collections.sort(names, (o1, o2) -> o2.length() - o1.length());
+ names.sort((o1, o2) -> o2.length() - o1.length());
// We're about to do many many String.replaceAll() so we do some
// checking first
diff --git a/framework/src/play/templates/TagContext.java b/framework/src/play/templates/TagContext.java
index 4b2177aaf4..7793b6ab00 100644
--- a/framework/src/play/templates/TagContext.java
+++ b/framework/src/play/templates/TagContext.java
@@ -11,8 +11,8 @@ public class TagContext {
private static final ThreadLocal> currentStack = new ThreadLocal<>();
- public String tagName;
- public Map data = new HashMap<>();
+ public final String tagName;
+ public final Map data = new HashMap<>();
public TagContext(String tagName) {
this.tagName = tagName;
diff --git a/framework/src/play/templates/TemplateCompiler.java b/framework/src/play/templates/TemplateCompiler.java
index c8e6d7d2cd..be77c23ed7 100644
--- a/framework/src/play/templates/TemplateCompiler.java
+++ b/framework/src/play/templates/TemplateCompiler.java
@@ -28,12 +28,12 @@ public BaseTemplate compile(VirtualFile file) {
return compile(new GroovyTemplate(file.relativePath(), file.contentAsString()));
}
- protected StringBuilder compiledSource = new StringBuilder();
+ protected final StringBuilder compiledSource = new StringBuilder();
+ protected final Stack tagsStack = new Stack<>();
protected BaseTemplate template;
protected TemplateParser parser;
protected boolean doNextScan = true;
protected TemplateParser.Token state;
- protected Stack tagsStack = new Stack<>();
protected int tagIndex;
protected boolean skipLineBreak;
protected int currentLine = 1;
diff --git a/framework/src/play/templates/TemplateLoader.java b/framework/src/play/templates/TemplateLoader.java
index 0982b25ad2..8a3c6b4582 100644
--- a/framework/src/play/templates/TemplateLoader.java
+++ b/framework/src/play/templates/TemplateLoader.java
@@ -17,12 +17,12 @@
public class TemplateLoader {
- protected static Map templates = new HashMap<>();
+ protected static final Map templates = new HashMap<>();
/**
* See getUniqueNumberForTemplateFile() for more info
*/
- private static AtomicLong nextUniqueNumber = new AtomicLong(1000);// we start on 1000
- private static Map templateFile2UniqueNumber = Collections.synchronizedMap(new HashMap());
+ private static final AtomicLong nextUniqueNumber = new AtomicLong(1000);// we start on 1000
+ private static final Map templateFile2UniqueNumber = Collections.synchronizedMap(new HashMap());
/**
* All loaded templates is cached in the templates-list using a key. This key is included as part of the classname
diff --git a/framework/src/play/templates/TemplateParser.java b/framework/src/play/templates/TemplateParser.java
index f5cf13298f..682dedb66b 100644
--- a/framework/src/play/templates/TemplateParser.java
+++ b/framework/src/play/templates/TemplateParser.java
@@ -5,7 +5,7 @@
*/
public class TemplateParser {
- private String pageSource;
+ private final String pageSource;
private int nestedBracesCounter; // counts nested braces in current expression/tag
public TemplateParser(String pageSource) {
diff --git a/framework/src/play/test/Fixtures.java b/framework/src/play/test/Fixtures.java
index e115c4b9b2..ceff21da2f 100644
--- a/framework/src/play/test/Fixtures.java
+++ b/framework/src/play/test/Fixtures.java
@@ -60,9 +60,9 @@ public class Fixtures {
*/
public static final String PROFILE_NAME = "Fixtures";
- static Pattern keyPattern = Pattern.compile("([^(]+)\\(([^)]+)\\)");
+ static final Pattern keyPattern = Pattern.compile("([^(]+)\\(([^)]+)\\)");
// Allows people to clear the cache, so Fixture is not stateful
- public static Map idCache = new HashMap<>();
+ public static final Map idCache = new HashMap<>();
public static void executeSQL(String sqlScript) {
for (CharSequence sql : new SQLSplitter(sqlScript)) {
@@ -138,7 +138,7 @@ public static void deleteAll() {
deleteDatabase();
}
- static String[] dontDeleteTheseTables = new String[] { "play_evolutions" };
+ static final String[] dontDeleteTheseTables = { "play_evolutions" };
/**
* Flush the entire JDBC database
@@ -540,8 +540,7 @@ static Map resolveDependencies(Class type, Map fields = new HashSet<>();
- Map resolvedYml = new HashMap<>();
- resolvedYml.putAll(yml);
+ Map resolvedYml = new HashMap<>(yml);
// Look up the super classes
Class> clazz = type;
diff --git a/framework/src/play/test/FunctionalTest.java b/framework/src/play/test/FunctionalTest.java
index 330d5ff08e..53e3825f36 100644
--- a/framework/src/play/test/FunctionalTest.java
+++ b/framework/src/play/test/FunctionalTest.java
@@ -53,7 +53,7 @@ public abstract class FunctionalTest extends BaseTest {
private static Map savedCookies; // cookies stored
// between calls
- private static Map renderArgs = new HashMap<>();
+ private static final Map renderArgs = new HashMap<>();
@Before
public void clearCookies() {
@@ -626,7 +626,7 @@ protected static URL reverse() {
public static class URL {
- ActionDefinition actionDefinition;
+ final ActionDefinition actionDefinition;
URL(ActionDefinition actionDefinition) {
this.actionDefinition = actionDefinition;
diff --git a/framework/src/play/test/Helpers.java b/framework/src/play/test/Helpers.java
index 08361646c8..a1b6a5fee2 100644
--- a/framework/src/play/test/Helpers.java
+++ b/framework/src/play/test/Helpers.java
@@ -5,7 +5,7 @@
public class Helpers {
- static Pattern pattern = Pattern.compile("^(\\w+)\\(\\s*(?:('(?:\\\\'|[^'])*'|[^.]+?)\\s*(?:,\\s*('(?:\\\\'|[^'])*'|[^.]+?)\\s*)?)?\\)$");
+ static final Pattern pattern = Pattern.compile("^(\\w+)\\(\\s*(?:('(?:\\\\'|[^'])*'|[^.]+?)\\s*(?:,\\s*('(?:\\\\'|[^'])*'|[^.]+?)\\s*)?)?\\)$");
public static String[] seleniumCommand(String command) {
Matcher matcher = pattern.matcher(command.trim());
diff --git a/framework/src/play/test/TestEngine.java b/framework/src/play/test/TestEngine.java
index 2c0623ae62..173b0b6791 100644
--- a/framework/src/play/test/TestEngine.java
+++ b/framework/src/play/test/TestEngine.java
@@ -39,7 +39,7 @@ public int compare(Class aClass, Class bClass) {
private static final ClassNameComparator classNameComparator = new ClassNameComparator();
- public static ExecutorService functionalTestsExecutor = Executors.newSingleThreadExecutor();
+ public static final ExecutorService functionalTestsExecutor = Executors.newSingleThreadExecutor();
public static List allUnitTests() {
List classes = new ArrayList<>();
@@ -55,7 +55,7 @@ public static List allUnitTests() {
}
}
}
- Collections.sort(classes, classNameComparator);
+ classes.sort(classNameComparator);
return classes;
}
@@ -63,13 +63,9 @@ public static List allFunctionalTests() {
List classes = new ArrayList<>();
classes.addAll(Play.classloader.getAssignableClasses(FunctionalTest.class));
classes.addAll(Play.pluginCollection.getFunctionalTests());
-
- for (ListIterator it = classes.listIterator(); it.hasNext();) {
- if (Modifier.isAbstract(it.next().getModifiers())) {
- it.remove();
- }
- }
- Collections.sort(classes, classNameComparator);
+
+ classes.removeIf(aClass -> Modifier.isAbstract(aClass.getModifiers()));
+ classes.sort(classNameComparator);
return classes;
}
@@ -197,9 +193,9 @@ public static TestResults run(String name) {
// ~~~~~~ Run listener
static class Listener extends RunListener {
- TestResults results;
+ final TestResults results;
+ final String className;
TestResult current;
- String className;
public Listener(String className, TestResults results) {
this.results = results;
diff --git a/framework/src/play/utils/Default.java b/framework/src/play/utils/Default.java
index 74bab120f5..0942879f91 100644
--- a/framework/src/play/utils/Default.java
+++ b/framework/src/play/utils/Default.java
@@ -2,7 +2,7 @@
public class Default {
- Object o;
+ final Object o;
public Default(Object o) {
this.o = o;
diff --git a/framework/src/play/utils/HTML.java b/framework/src/play/utils/HTML.java
index 68bd2ac380..9099c737d4 100644
--- a/framework/src/play/utils/HTML.java
+++ b/framework/src/play/utils/HTML.java
@@ -110,7 +110,7 @@ public HtmlCharacterEntityReferences() {
int index = (referredChar < 1000 ? referredChar : referredChar - 7000);
String reference = entityReferences.getProperty(key);
this.characterToEntityReferenceMap[index] = REFERENCE_START + reference + REFERENCE_END;
- this.entityReferenceToCharacterMap.put(reference, new Character((char) referredChar));
+ this.entityReferenceToCharacterMap.put(reference, (char) referredChar);
}
}
diff --git a/framework/src/play/utils/Java.java b/framework/src/play/utils/Java.java
index d718777d34..5fc7111f0e 100644
--- a/framework/src/play/utils/Java.java
+++ b/framework/src/play/utils/Java.java
@@ -18,6 +18,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.concurrent.FutureTask;
@@ -316,7 +317,7 @@ public static void findAllFields(Class clazz, Set found) {
}
/** cache */
- private static Map wrappers = new HashMap<>();
+ private static final Map wrappers = new HashMap<>();
public static FieldWrapper getFieldWrapper(Field field) {
if (wrappers.get(field) == null) {
@@ -473,12 +474,7 @@ public boolean equals(Object o) {
ClassAndAnnotation that = (ClassAndAnnotation) o;
- if (annotation != null ? !annotation.equals(that.annotation) : that.annotation != null)
- return false;
- if (clazz != null ? !clazz.equals(that.clazz) : that.clazz != null)
- return false;
-
- return true;
+ return Objects.equals(annotation, that.annotation) && Objects.equals(clazz, that.clazz);
}
@Override
@@ -543,7 +539,7 @@ public List findAllAnnotatedMethods(Class> clazz, Class extends Anno
private void sortByPriority(List methods, final Class extends Annotation> annotationType) {
try {
final Method priority = annotationType.getMethod("priority");
- sort(methods, (m1, m2) -> {
+ methods.sort((m1, m2) -> {
try {
Integer priority1 = (Integer) priority.invoke(m1.getAnnotation(annotationType));
Integer priority2 = (Integer) priority.invoke(m2.getAnnotation(annotationType));
diff --git a/framework/src/play/utils/SmartFuture.java b/framework/src/play/utils/SmartFuture.java
index bed603982a..a6e86246ba 100644
--- a/framework/src/play/utils/SmartFuture.java
+++ b/framework/src/play/utils/SmartFuture.java
@@ -42,7 +42,7 @@ public V get(long timeout, TimeUnit unit) throws InterruptedException, Execution
// Callbacks
- private List> callbacks = new ArrayList<>();
+ private final List> callbacks = new ArrayList<>();
private boolean invoked = false;
private V result = null;
diff --git a/framework/src/play/utils/Utils.java b/framework/src/play/utils/Utils.java
index fd2aefffb6..a5b0f7ba84 100644
--- a/framework/src/play/utils/Utils.java
+++ b/framework/src/play/utils/Utils.java
@@ -175,11 +175,10 @@ public static void kill(String pid) throws Exception {
public static class AlternativeDateFormat {
- Locale locale;
- List formats = new ArrayList<>();
+ final List formats = new ArrayList<>();
+ final Locale locale;
public AlternativeDateFormat(Locale locale, String... alternativeFormats) {
- super();
this.locale = locale;
setFormats(alternativeFormats);
}
diff --git a/framework/src/play/vfs/VirtualFile.java b/framework/src/play/vfs/VirtualFile.java
index 8cb4096287..95d55084e6 100644
--- a/framework/src/play/vfs/VirtualFile.java
+++ b/framework/src/play/vfs/VirtualFile.java
@@ -30,7 +30,7 @@
*/
public class VirtualFile {
- File realFile;
+ final File realFile;
VirtualFile(File file) {
this.realFile = file;
diff --git a/framework/test-src/play/db/SQLSplitterTest.java b/framework/test-src/play/db/SQLSplitterTest.java
index c1f2851cd9..ff6f226dde 100644
--- a/framework/test-src/play/db/SQLSplitterTest.java
+++ b/framework/test-src/play/db/SQLSplitterTest.java
@@ -2,6 +2,7 @@
import org.junit.*;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import java.io.File;
@@ -110,11 +111,11 @@ public void verifyTestSplitting() throws Exception {
CharSequence[] srcArr = new CharSequence[(int) srcArrList.size()];
srcArr = srcArrList.toArray(srcArr);
- assertEquals(readFile("/play/db/test.out.sql").split("==="), srcArr);
+ assertArrayEquals(readFile("/play/db/test.out.sql").split("==="), srcArr);
srcArrList = SQLSplitter.splitSQL(readFile("/play/db/test2.sql"));
srcArr = new CharSequence[(int) srcArrList.size()];
srcArr = srcArrList.toArray(srcArr);
- assertEquals(readFile("/play/db/test2.out.sql").split("==="), srcArr);
+ assertArrayEquals(readFile("/play/db/test2.out.sql").split("==="), srcArr);
}
}
diff --git a/framework/test-src/play/test/PlayJUnitRunnerTest.java b/framework/test-src/play/test/PlayJUnitRunnerTest.java
index ea2ea8a45b..56770d9350 100644
--- a/framework/test-src/play/test/PlayJUnitRunnerTest.java
+++ b/framework/test-src/play/test/PlayJUnitRunnerTest.java
@@ -1,7 +1,7 @@
package play.test;
import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -17,7 +17,7 @@ public class PlayJUnitRunnerTest {
public void testFilter() throws Exception {
PlayJUnitRunner runner = mock(PlayJUnitRunner.class);
runner.jUnit4 = new JUnit4(PlayJUnitRunnerTest.class);
- doCallRealMethod().when(runner).filter((Filter) any());
+ doCallRealMethod().when(runner).filter(any());
runner.filter(new Filter() {
diff --git a/modules/crud/app/controllers/CRUD.java b/modules/crud/app/controllers/CRUD.java
index f0294073e3..0b7b1a65c0 100644
--- a/modules/crud/app/controllers/CRUD.java
+++ b/modules/crud/app/controllers/CRUD.java
@@ -79,7 +79,7 @@ public static void attachment(String id, String field) throws Exception {
Object att = object.getClass().getField(field).get(object);
if(att instanceof Model.BinaryField) {
Model.BinaryField attachment = (Model.BinaryField)att;
- if (attachment == null || !attachment.exists()) {
+ if (!attachment.exists()) {
notFound();
}
response.contentType = attachment.type();
@@ -88,7 +88,7 @@ public static void attachment(String id, String field) throws Exception {
// DEPRECATED
if(att instanceof play.db.jpa.FileAttachment) {
play.db.jpa.FileAttachment attachment = (play.db.jpa.FileAttachment)att;
- if (attachment == null || !attachment.exists()) {
+ if (!attachment.exists()) {
notFound();
}
renderBinary(attachment.get(), attachment.filename);
@@ -274,13 +274,13 @@ public Object getBlankAction() {
public Long count(String search, String searchFields, String where) {
- return factory.count(searchFields == null ? new ArrayList() : Arrays.asList(searchFields.split("[ ]")), search, where);
+ return factory.count(searchFields == null ? new ArrayList() : Arrays.asList(searchFields.split(" ")), search, where);
}
@SuppressWarnings("unchecked")
public List findPage(int page, String search, String searchFields, String orderBy, String order, String where) {
int offset = (page - 1) * getPageSize();
- List properties = searchFields == null ? new ArrayList(0) : Arrays.asList(searchFields.split("[ ]"));
+ List properties = searchFields == null ? new ArrayList(0) : Arrays.asList(searchFields.split(" "));
return Model.Manager.factoryFor(entityClass).fetch(offset, getPageSize(), orderBy, order, properties, search, where);
}
diff --git a/modules/docviewer/app/helpers/CheatSheetHelper.java b/modules/docviewer/app/helpers/CheatSheetHelper.java
index 82df469eb5..f2675112b0 100644
--- a/modules/docviewer/app/helpers/CheatSheetHelper.java
+++ b/modules/docviewer/app/helpers/CheatSheetHelper.java
@@ -21,27 +21,18 @@ public static File[] getSheets(String category, String docLang) {
}
if (cheatSheetDir.exists() && cheatSheetDir.isDirectory()) {
- File[] sheetFiles = cheatSheetDir.listFiles(new FileFilter() {
-
- public boolean accept(File pathname) {
- return pathname.isFile() && pathname.getName().endsWith(".textile");
- }
- });
+ File[] sheetFiles = cheatSheetDir.listFiles(pathname -> pathname.isFile() && pathname.getName().endsWith(".textile"));
// first letters of file name before "-" serves as sort index
- Arrays.sort(sheetFiles, new Comparator() {
-
- public int compare(File f1, File f2) {
-
- String o1 = f1.getName();
- String o2 = f2.getName();
-
- if (o1.contains("-") && o2.contains("-")) {
- return o1.substring(0, o1.indexOf("-"))
- .compareTo(o2.substring(0, o1.indexOf("-")));
- } else {
- return o1.compareTo(o2);
- }
+ Arrays.sort(sheetFiles, (f1, f2) -> {
+ String o1 = f1.getName();
+ String o2 = f2.getName();
+
+ if (o1.contains("-") && o2.contains("-")) {
+ return o1.substring(0, o1.indexOf("-"))
+ .compareTo(o2.substring(0, o1.indexOf("-")));
+ } else {
+ return o1.compareTo(o2);
}
});
@@ -73,18 +64,10 @@ public static String getCategoryTitle(String category) {
public static Map listCategoriesAndTitles(String docLang) {
String docLangDir = (docLang != null && (!"en".equalsIgnoreCase(docLang) && !docLang.matches("en-.*"))) ? "_" + docLang : "";
- File[] categories = new File(cheatSheetBaseDir + docLangDir).listFiles(new FileFilter() {
- public boolean accept(File pathname) {
- return pathname.isDirectory();
- }
- });
+ File[] categories = new File(cheatSheetBaseDir + docLangDir).listFiles(File::isDirectory);
if(categories==null || categories.length<=0){
- categories = cheatSheetBaseDir.listFiles(new FileFilter() {
- public boolean accept(File pathname) {
- return pathname.isDirectory();
- }
- });
+ categories = cheatSheetBaseDir.listFiles(File::isDirectory);
}
Arrays.sort(categories);
diff --git a/modules/docviewer/app/helpers/LangMenuHelper.java b/modules/docviewer/app/helpers/LangMenuHelper.java
index 20871145bc..3a7527ac76 100644
--- a/modules/docviewer/app/helpers/LangMenuHelper.java
+++ b/modules/docviewer/app/helpers/LangMenuHelper.java
@@ -20,12 +20,7 @@ public static List getMenuList() {
defaultLangMenu.key = "en";
defaultLangMenu.value = "English";
langMenuList.add(defaultLangMenu);
- File[] dirs = baseDir.listFiles(new FileFilter() {
- @Override
- public boolean accept(File file) {
- return file.isDirectory() && ptn.matcher(file.getName()).find();
- }
- });
+ File[] dirs = baseDir.listFiles(file -> file.isDirectory() && ptn.matcher(file.getName()).find());
for (final File dir : dirs) {
Matcher m = ptn.matcher(dir.getName());
String langCd = "";
diff --git a/modules/testrunner/src/play/modules/testrunner/FirePhoque.java b/modules/testrunner/src/play/modules/testrunner/FirePhoque.java
index 9d61b93456..906bbf5acf 100644
--- a/modules/testrunner/src/play/modules/testrunner/FirePhoque.java
+++ b/modules/testrunner/src/play/modules/testrunner/FirePhoque.java
@@ -17,6 +17,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
@@ -47,18 +48,18 @@ public static void main(String[] args) throws Exception {
if(runUnitTests != null || runFunctionalTests != null || runSeleniumTests != null){
urlStringBuilder.append("?");
- urlStringBuilder.append("runUnitTests=").append(runUnitTests != null ? true : false);
- System.out.println("~ Run unit tests:" + (runUnitTests != null ? true : false));
+ urlStringBuilder.append("runUnitTests=").append(runUnitTests != null);
+ System.out.println("~ Run unit tests:" + (runUnitTests != null));
- urlStringBuilder.append("&runFunctionalTests=").append(runFunctionalTests != null ? true : false);
- System.out.println("~ Run functional tests:" + (runFunctionalTests != null ? true : false));
+ urlStringBuilder.append("&runFunctionalTests=").append(runFunctionalTests != null);
+ System.out.println("~ Run functional tests:" + (runFunctionalTests != null));
- urlStringBuilder.append("&runSeleniumTests=").append(runSeleniumTests != null ? true : false);
- System.out.println("~ Run selenium tests:" + (runSeleniumTests != null ? true : false));
+ urlStringBuilder.append("&runSeleniumTests=").append(runSeleniumTests != null);
+ System.out.println("~ Run selenium tests:" + (runSeleniumTests != null));
}
try {
- in = new BufferedReader(new InputStreamReader(new URL(urlStringBuilder.toString()).openStream(), "utf-8"));
+ in = new BufferedReader(new InputStreamReader(new URL(urlStringBuilder.toString()).openStream(), StandardCharsets.UTF_8));
String marker = in.readLine();
if (!marker.equals("---")) {
throw new RuntimeException("Oops");