Skip to content

Commit

Permalink
[#1823] Fix play.exceptions.CompilationException
Browse files Browse the repository at this point in the history
  • Loading branch information
xael-fry committed Aug 4, 2014
1 parent de29d52 commit feda38e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
25 changes: 19 additions & 6 deletions framework/src/play/classloading/ApplicationClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ public void clear() {
* @return The ApplicationClass or null
*/
public ApplicationClass getApplicationClass(String name) {
if (!classes.containsKey(name) && getJava(name) != null) {
classes.put(name, new ApplicationClass(name));
VirtualFile javaFile = getJava(name);
if(javaFile != null){
if (!classes.containsKey(name)) {
classes.put(name, new ApplicationClass(name));
}
return classes.get(name);
}
return classes.get(name);
return null;
}

/**
Expand Down Expand Up @@ -323,10 +327,19 @@ public static VirtualFile getJava(String name) {
if (fileName.contains("$")) {
fileName = fileName.substring(0, fileName.indexOf("$"));
}
fileName = fileName.replace(".", "/") + ".java";
// the local variable fileOrDir is important!
String fileOrDir = fileName.replace(".", "/");
fileName = fileOrDir + ".java";
for (VirtualFile path : Play.javaPath) {
VirtualFile javaFile = path.child(fileName);
if (javaFile.exists()) {
// 1. check if there is a folder (without extension)
VirtualFile javaFile = path.child(fileOrDir);

if (javaFile.exists() && javaFile.isDirectory() && javaFile.matchName(fileName)) {
return javaFile;
}
// 2. check if there is a file
javaFile = path.child(fileName);
if (javaFile.exists() && javaFile.matchName(fileName)) {
return javaFile;
}
}
Expand Down
19 changes: 16 additions & 3 deletions framework/src/play/classloading/ApplicationClassloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import play.Logger;
import play.Play;
import play.classloading.hash.ClassStateHashCreator;
Expand Down Expand Up @@ -201,8 +202,8 @@ private void loadPackage(String className) {
} else {
className = "package-info";
}
if (findLoadedClass(className) == null) {
loadApplicationClass(className);
if (this.findLoadedClass(className) == null) {
this.loadApplicationClass(className);
}
}

Expand All @@ -211,7 +212,7 @@ private void loadPackage(String className) {
*/
protected byte[] getClassDefinition(String name) {
name = name.replace(".", "/") + ".class";
InputStream is = getResourceAsStream(name);
InputStream is = this.getResourceAsStream(name);
if (is == null) {
return null;
}
Expand Down Expand Up @@ -245,6 +246,18 @@ public InputStream getResourceAsStream(String name) {
return res.inputstream();
}
}
URL url = this.getResource(name);
if (url != null) {

This comment has been minimized.

Copy link
@flybyray

flybyray Mar 8, 2018

Contributor

nice try. but this check needs to be done within getResource.
i will open a new issue for the closed #786 and show why it needs modification

try {
File file = new File(url.toURI());
String fileName = file.getCanonicalFile().getName();
if (!name.endsWith(fileName)) {
return null;
}
} catch (Exception e) {
}
}

return super.getResourceAsStream(name);
}

Expand Down
19 changes: 19 additions & 0 deletions framework/src/play/vfs/VirtualFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,23 @@ public static VirtualFile fromRelativePath(String relativePath) {

return null;
}

/**
* Method to check if the name really match (very useful on system without case sensibility (like windows))
* @param fileName
* @return true if match
*/
public boolean matchName(String fileName) {
// we need to check the name case to be sure we is not conflict with a file with the same name
String canonicalName = null;
try {
canonicalName = this.realFile.getCanonicalFile().getName();
} catch (IOException e) {
}
// Name case match
if (fileName != null && canonicalName != null && fileName.endsWith(canonicalName)) {
return true;
}
return false;
}
}

0 comments on commit feda38e

Please sign in to comment.