@@ -151,8 +151,12 @@ public static boolean isCharLegal(char c) {
151151 }
152152
153153 /**
154- * Converts a relative filename to an absolute one, if necessary. Returns
155- * an empty optional if the file does not exist.
154+ * Converts a relative filename to an absolute one, if necessary.
155+ *
156+ * @param fileName the filename (e.g., a .pdf file), may contain path separators
157+ * @param directory the directory which should be search starting point
158+ *
159+ * @returns an empty optional if the file does not exist, otherwise, the absolute path
156160 */
157161 public static Optional <Path > find (String fileName , Path directory ) {
158162 Objects .requireNonNull (fileName );
@@ -166,11 +170,15 @@ public static Optional<Path> find(String fileName, Path directory) {
166170 if (fileName .isEmpty ()) {
167171 return Optional .of (directory );
168172 }
173+
174+ Path resolvedFile = directory .resolve (fileName );
175+ if (Files .exists (resolvedFile )) {
176+ return Optional .of (resolvedFile );
177+ }
178+
169179 // get the furthest path element from root and check if our filename starts with the same name
170180 // workaround for old JabRef behavior
171181 String furthestDirFromRoot = directory .getFileName ().toString ();
172- Path resolvedFile = directory .resolve (fileName );
173-
174182 if (fileName .startsWith (furthestDirFromRoot )) {
175183 resolvedFile = directory .resolveSibling (fileName );
176184 }
0 commit comments