--- old/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ModuleFinder.java 2017-02-08 11:44:46.153925139 -0800 +++ new/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ModuleFinder.java 2017-02-08 11:44:46.014924095 -0800 @@ -267,6 +267,7 @@ private List scanModulePath(ModuleSymbol toFind) { ListBuffer results = new ListBuffer<>(); Map namesInSet = new HashMap<>(); + boolean multiModuleMode = fileManager.hasLocation(StandardLocation.MODULE_SOURCE_PATH); while (moduleLocationIterator.hasNext()) { Set locns = (moduleLocationIterator.next()); namesInSet.clear(); @@ -279,22 +280,39 @@ // module has already been found, so ignore this instance continue; } + if (fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH) && + msym.patchLocation == null) { + msym.patchLocation = + fileManager.getLocationForModule(StandardLocation.PATCH_MODULE_PATH, + msym.name.toString()); + checkModuleInfoOnLocation(msym.patchLocation, Kind.CLASS, Kind.SOURCE); + if (msym.patchLocation != null && + multiModuleMode && + fileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) { + msym.patchOutputLocation = + fileManager.getLocationForModule(StandardLocation.CLASS_OUTPUT, + msym.name.toString()); + checkModuleInfoOnLocation(msym.patchOutputLocation, Kind.CLASS); + } + } if (moduleLocationIterator.outer == StandardLocation.MODULE_SOURCE_PATH) { - msym.sourceLocation = l; - if (fileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) { - msym.classLocation = fileManager.getLocationForModule(StandardLocation.CLASS_OUTPUT, msym.name.toString()); + if (msym.patchLocation == null) { + msym.sourceLocation = l; + if (fileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) { + msym.classLocation = + fileManager.getLocationForModule(StandardLocation.CLASS_OUTPUT, + msym.name.toString()); + } } } else { msym.classLocation = l; } - if (fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH)) { - msym.patchLocation = fileManager.getLocationForModule(StandardLocation.PATCH_MODULE_PATH, msym.name.toString()); - } if (moduleLocationIterator.outer == StandardLocation.SYSTEM_MODULES || moduleLocationIterator.outer == StandardLocation.UPGRADE_MODULE_PATH) { msym.flags_field |= Flags.SYSTEM_MODULE; } - if (toFind == msym || toFind == null) { + if (toFind == null || + (toFind == msym && (msym.sourceLocation != null || msym.classLocation != null))) { // Note: cannot return msym directly, because we must finish // processing this set first results.add(msym); @@ -314,6 +332,21 @@ return results.toList(); } + private void checkModuleInfoOnLocation(Location location, Kind... kinds) throws IOException { + if (location == null) + return ; + + for (Kind kind : kinds) { + JavaFileObject file = fileManager.getJavaFileForInput(location, + names.module_info.toString(), + kind); + if (file != null) { + log.error(Errors.LocnModuleInfoNotAllowedOnPatchPath(file)); + return ; + } + } + } + private void findModuleInfo(ModuleSymbol msym) { try { JavaFileObject src_fo = (msym.sourceLocation == null) ? null