Skip to content

Commit 8f818c0

Browse files
committed
added more checks to the code that finds the project root
1 parent ddcdada commit 8f818c0

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

soot-infoflow/test/soot/jimple/infoflow/test/junit/JUnitTests.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import org.junit.Assume;
2424
import org.junit.Before;
2525
import org.junit.BeforeClass;
26+
import org.slf4j.Logger;
27+
import org.slf4j.LoggerFactory;
2628

2729
import soot.jimple.infoflow.AbstractInfoflow;
2830
import soot.jimple.infoflow.BackwardsInfoflow;
@@ -41,6 +43,8 @@
4143
*/
4244
public abstract class JUnitTests extends AbstractJUnitTests {
4345

46+
protected static final Logger logger = LoggerFactory.getLogger(JUnitTests.class);
47+
4448
protected static String appPath, libPath;
4549

4650
protected static List<String> sinks;
@@ -206,12 +210,19 @@ protected void onlyForwards(IInfoflow infoflow, String message) {
206210
* @throws IOException
207211
*/
208212
public static File getInfoflowRoot(Class<?> referenceClass) throws IOException {
209-
File f = new File(referenceClass.getProtectionDomain().getCodeSource().getLocation().getPath());
213+
File classFile = new File(referenceClass.getProtectionDomain().getCodeSource().getLocation().getPath());
214+
File f = classFile;
210215
if (f.exists()) {
211216
while (!f.getName().equals("soot-infoflow") && f.getParentFile() != null)
212217
f = f.getParentFile();
213-
return f;
214-
}
218+
219+
// The project root must exist and must not be the file system root
220+
if (f.exists() && f.getParentFile() != null)
221+
return f;
222+
223+
logger.warn("Finding project root from class file {} failed", classFile);
224+
} else
225+
logger.warn("Class file {} does not exist", classFile);
215226
return getInfoflowRoot();
216227
}
217228

0 commit comments

Comments
 (0)