Skip to content
Open

Cleanup #1550

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions framework/src/play/Invoker.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package play;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
Expand All @@ -26,6 +25,8 @@
import play.libs.F.Promise;
import play.utils.PThreadFactory;

import static java.util.Collections.unmodifiableList;

/**
* Run some code in a Play! context
*/
Expand Down Expand Up @@ -115,8 +116,7 @@ public static InvocationContext current() {
}

public InvocationContext(String invocationType) {
this.invocationType = invocationType;
this.annotations = new ArrayList<>();
this(invocationType, List.of());
}

public InvocationContext(String invocationType, List<Annotation> annotations) {
Expand All @@ -125,16 +125,11 @@ public InvocationContext(String invocationType, List<Annotation> annotations) {
}

public InvocationContext(String invocationType, Annotation[] annotations) {
this.invocationType = invocationType;
this.annotations = Arrays.asList(annotations);
this(invocationType, List.of(annotations));
}

public InvocationContext(String invocationType, Annotation[]... annotations) {
this.invocationType = invocationType;
this.annotations = new ArrayList<>();
for (Annotation[] some : annotations) {
this.annotations.addAll(Arrays.asList(some));
}
this(invocationType, Arrays.stream(annotations).flatMap(Arrays::stream).toList());
}

public List<Annotation> getAnnotations() {
Expand All @@ -144,7 +139,7 @@ public List<Annotation> getAnnotations() {
@SuppressWarnings("unchecked")
public <T extends Annotation> T getAnnotation(Class<T> clazz) {
for (Annotation annotation : annotations) {
if (annotation.annotationType().isAssignableFrom(clazz)) {
if (annotation.annotationType() == clazz) {
return (T) annotation;
}
}
Expand All @@ -153,7 +148,7 @@ public <T extends Annotation> T getAnnotation(Class<T> clazz) {

public <T extends Annotation> boolean isAnnotationPresent(Class<T> clazz) {
for (Annotation annotation : annotations) {
if (annotation.annotationType().isAssignableFrom(clazz)) {
if (annotation.annotationType() == clazz) {
return true;
}
}
Expand Down Expand Up @@ -366,7 +361,7 @@ public InvocationContext getInvocationContext() {
*/
static {
int core = Integer.parseInt(Play.configuration.getProperty("play.pool",
Play.mode == Mode.DEV ? "1" : ((Runtime.getRuntime().availableProcessors() + 1) + "")));
Play.mode == Mode.DEV ? "1" : Integer.toString(Runtime.getRuntime().availableProcessors() + 1)));
executor = new ScheduledThreadPoolExecutor(core, new PThreadFactory("play"), new ThreadPoolExecutor.AbortPolicy());
}

Expand Down
2 changes: 1 addition & 1 deletion framework/src/play/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ static boolean niceThrowable(org.apache.logging.log4j.Level level, Throwable e,
}
cleanTrace.add(se);
}
toClean.setStackTrace(cleanTrace.toArray(new StackTraceElement[cleanTrace.size()]));
toClean.setStackTrace(cleanTrace.toArray(StackTraceElement[]::new));
toClean = toClean.getCause();
if (toClean == null) {
break;
Expand Down
10 changes: 5 additions & 5 deletions framework/src/play/Play.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,13 @@ private static Properties readOneConfigurationFile(String filename) {
Properties newConfiguration = new OrderSafeProperties();
Pattern pattern = Pattern.compile("^%([a-zA-Z0-9_\\-]+)\\.(.*)$");
for (Object key : propsFromFile.keySet()) {
Matcher matcher = pattern.matcher(key + "");
Matcher matcher = pattern.matcher(String.valueOf(key));
if (!matcher.matches()) {
newConfiguration.put(key, propsFromFile.get(key).toString().trim());
}
}
for (Object key : propsFromFile.keySet()) {
Matcher matcher = pattern.matcher(key + "");
Matcher matcher = pattern.matcher(String.valueOf(key));
if (matcher.matches()) {
String instance = matcher.group(1);
if (instance.equals(id)) {
Expand Down Expand Up @@ -512,7 +512,7 @@ public static synchronized void start() {

// Locales
langs = new ArrayList<>(Arrays.asList(configuration.getProperty("application.langs", "").split(",")));
if (langs.size() == 1 && langs.get(0).trim().length() == 0) {
if (langs.size() == 1 && langs.get(0).isBlank()) {
langs = new ArrayList<>(16);
}

Expand All @@ -521,7 +521,7 @@ public static synchronized void start() {

// SecretKey
secretKey = configuration.getProperty("application.secret", "").trim();
if (secretKey.length() == 0) {
if (secretKey.isEmpty()) {
Logger.warn("No secret key defined. Sessions will not be encrypted");
}

Expand Down Expand Up @@ -729,7 +729,7 @@ public static void loadModules() {
public static void loadModules(VirtualFile appRoot) {
if (System.getenv("MODULES") != null) {
// Modules path is prepended with a env property
if (System.getenv("MODULES") != null && System.getenv("MODULES").trim().length() > 0) {
if (System.getenv("MODULES") != null && !System.getenv("MODULES").isBlank()) {

for (String m : System.getenv("MODULES").split(File.pathSeparator)) {
File modulePath = new File(m);
Expand Down
4 changes: 2 additions & 2 deletions framework/src/play/PlayPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,8 @@ public String getName() {

// I don't want to add any additional dependencies to the project or use JDK 8 features
// so I'm just rolling my own 1 arg function interface... there must be a better way to do this...
public static interface Function1<I, O> {
public O apply(I arg) throws Throwable;
public interface Function1<I, O> {
O apply(I arg) throws Throwable;
}
}

Expand Down
4 changes: 2 additions & 2 deletions framework/src/play/ant/PlayConfigurationLoadTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ private Map<String, String> properties() {
continue;
}
if (line.startsWith("%")) {
if (playId.length() > 0 && line.startsWith(playId + ".")) {
line = line.substring((playId + ".").length());
if (!playId.isEmpty() && line.startsWith(playId + '.')) {
line = line.substring(playId.length() + 1);
String[] sa = splitLine(line);
if (sa != null) {
idSpecific.put(sa[0], sa[1]);
Expand Down
28 changes: 14 additions & 14 deletions framework/src/play/cache/CacheImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@
*/
public interface CacheImpl {

public void add(String key, Object value, int expiration);
void add(String key, Object value, int expiration);

public boolean safeAdd(String key, Object value, int expiration);
boolean safeAdd(String key, Object value, int expiration);

public void set(String key, Object value, int expiration);
void set(String key, Object value, int expiration);

public boolean safeSet(String key, Object value, int expiration);
boolean safeSet(String key, Object value, int expiration);

public void replace(String key, Object value, int expiration);
void replace(String key, Object value, int expiration);

public boolean safeReplace(String key, Object value, int expiration);
boolean safeReplace(String key, Object value, int expiration);

public Object get(String key);
Object get(String key);

public Map<String, Object> get(String[] keys);
Map<String, Object> get(String[] keys);

public long incr(String key, int by);
long incr(String key, int by);

public long decr(String key, int by);
long decr(String key, int by);

public void clear();
void clear();

public void delete(String key);
void delete(String key);

public boolean safeDelete(String key);
boolean safeDelete(String key);

public void stop();
void stop();
}
2 changes: 1 addition & 1 deletion framework/src/play/cache/CacheKeyGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
* Allow custom cache key to be used by applications.
*/
public interface CacheKeyGenerator {
public String generate(Request request);
String generate(Request request);
}
2 changes: 1 addition & 1 deletion framework/src/play/classloading/ApplicationClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public static class ApplicationClass {
/**
* Last time than this class was compiled
*/
public Long timestamp = 0L;
public long timestamp = 0L;
/**
* Is this class compiled
*/
Expand Down
6 changes: 3 additions & 3 deletions framework/src/play/classloading/ApplicationClassloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public void detectChanges() throws RestartNeededException {
Cache.clear();
if (HotswapAgent.enabled) {
try {
HotswapAgent.reload(newDefinitions.toArray(new ClassDefinition[newDefinitions.size()]));
HotswapAgent.reload(newDefinitions.toArray(ClassDefinition[]::new));
} catch (Throwable e) {
throw new RestartNeededException(newDefinitions.size() + " classes changed", e);
}
Expand Down Expand Up @@ -416,7 +416,7 @@ public List<Class<?>> getAllClasses() {
}
}

Play.classes.compiler.compile(classNames.toArray(new String[classNames.size()]));
Play.classes.compiler.compile(classNames.toArray(String[]::new));

}

Expand Down Expand Up @@ -521,7 +521,7 @@ private List<ApplicationClass> getAllClasses(VirtualFile path) {
}

private List<ApplicationClass> getAllClasses(VirtualFile path, String basePackage) {
if (basePackage.length() > 0 && !basePackage.endsWith(".")) {
if (!basePackage.isEmpty() && !basePackage.endsWith(".")) {
basePackage += ".";
}
List<ApplicationClass> res = new ArrayList<>();
Expand Down
49 changes: 20 additions & 29 deletions framework/src/play/classloading/BytecodeCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.security.MessageDigest;
import java.util.HexFormat;
import java.util.regex.Pattern;

import static java.nio.charset.StandardCharsets.UTF_8;
Expand Down Expand Up @@ -51,27 +52,26 @@ public static byte[] getBytecode(String name, String source) {
}
File f = cacheFile(REPLACED_CHARS.matcher(name).replaceAll("_"));
if (f.exists()) {
FileInputStream fis = new FileInputStream(f);
// Read hash
int offset = 0;
int read = -1;
StringBuilder hash = new StringBuilder();
// look for null byte, or end-of file
while ((read = fis.read()) > 0) {
hash.append((char) read);
offset++;
}
if (!hash(source).contentEquals(hash)) {
if (Logger.isTraceEnabled()) {
Logger.trace("Bytecode too old (%s != %s)", hash, hash(source));
try (FileInputStream fis = new FileInputStream(f)) {
// Read hash
int offset = 0;
int read;
StringBuilder hash = new StringBuilder();
// look for null byte, or end-of file
while ((read = fis.read()) > 0) {
hash.append((char) read);
offset++;
}
if (!hash(source).contentEquals(hash)) {
if (Logger.isTraceEnabled()) {
Logger.trace("Bytecode too old (%s != %s)", hash, hash(source));
}
return null;
}
fis.close();
return null;
byte[] byteCode = new byte[(int) f.length() - (offset + 1)];
fis.read(byteCode);
return byteCode;
}
byte[] byteCode = new byte[(int) f.length() - (offset + 1)];
fis.read(byteCode);
fis.close();
return byteCode;
}

if (Logger.isTraceEnabled()) {
Expand Down Expand Up @@ -127,18 +127,9 @@ static String hash(String text) {
plugins.append(plugin.getClass().getName());
}
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.reset();
messageDigest.update((Play.version + plugins + text).getBytes(UTF_8));
byte[] digest = messageDigest.digest();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < digest.length; ++i) {
int value = digest[i];
if (value < 0) {
value += 256;
}
builder.append(Integer.toHexString(value));
}
return builder.toString();
return HexFormat.of().formatHex(digest);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void edit(Handler handler) throws CannotCompileException {
/**
* Mark class that need controller enhancement
*/
public static interface ControllerSupport {
public interface ControllerSupport {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void enhanceThisClass(ApplicationClass applicationClass) throws Exception

try {
// The instruction at which this local variable has been created
Integer pc = localVariableAttribute.startPc(i);
int pc = localVariableAttribute.startPc(i);

// Move to the next instruction (insertionPc)
CodeIterator codeIterator = codeAttribute.iterator();
Expand Down
Loading
Loading