8236842: Surprising 'multiple elements' behaviour from getTypeElement when cross-compiling with --release #200
Conversation
… when cross-compiling with --release
|
@lahodaj The command |
@lahodaj The following label will be automatically applied to this pull request: When this pull request is ready to be reviewed, an RFR email will be sent to the corresponding mailing list. If you would like to change these labels, use the |
Webrevs
|
/csr JDK-8253168 |
/csr needed |
@lahodaj has indicated that a compatibility and specification (CSR) request is needed for this pull request. |
/csr unneeded |
/csr needed |
@lahodaj this pull request will not be integrated until the CSR request JDK-8253168 for issue JDK-8236842 has been approved. |
I have also made some small edits to the CSR and added myself as reviewer |
* | ||
* If running with modules, packages of the given name are searched in a | ||
* two-stage process: | ||
* -find non-empty packages with the given name returned by {@link #getPackageElement(ModuleElement, CharSequence)}, where the provided ModuleSymbol is any root module, |
vicente-romero-oracle
Sep 16, 2020
Contributor
it would be nice to try to keep the line width as close as possible to 80 chars, same for the CSR
it would be nice to try to keep the line width as close as possible to 80 chars, same for the CSR
* | ||
* If running with modules, type elements of the given name are searched in a | ||
* two-stage process: | ||
* -find type elements with the given name returned by {@link #getTypeElement(ModuleElement, CharSequence)}, where the provided ModuleSymbol is any root module, |
vicente-romero-oracle
Sep 16, 2020
Contributor
same comment as above
same comment as above
@@ -199,42 +200,44 @@ private ClassSymbol doGetTypeElement(ModuleElement module, CharSequence name) { | |||
return (S) resultCache.computeIfAbsent(Pair.of(methodName, nameStr), p -> { | |||
Set<S> found = new LinkedHashSet<>(); | |||
|
|||
for (ModuleSymbol msym : modules.allModules()) { | |||
S sym = nameToSymbol(msym, nameStr, clazz); | |||
for (Set<ModuleSymbol> allModules : Arrays.asList(modules.getRootModules(), modules.allModules())) { |
vicente-romero-oracle
Sep 16, 2020
•
Contributor
does it make sense to obtain a diff between the the root modules and the all-modules set in order to avoid searching twice in the root modules if the symbol is not found there in the first try?
does it make sense to obtain a diff between the the root modules and the all-modules set in order to avoid searching twice in the root modules if the symbol is not found there in the first try?
} | ||
return Optional.empty(); | ||
} else { | ||
//not found, try another option |
vicente-romero-oracle
Sep 16, 2020
Contributor
probably this else {} can be removed right?
probably this else {} can be removed right?
lahodaj
Sep 17, 2020
Author
Contributor
It could be removed, but I added it intentionally to make it clear the "else" option has been considered, and is intentional. I can remove it, if you strongly prefer, though.
It could be removed, but I added it intentionally to make it clear the "else" option has been considered, and is intentional. I can remove it, if you strongly prefer, though.
… of modules that have already been searched.
@vicente-romero-oracle thanks for the comments! I've updated the patch and CSR based on the comments. |
I'm OK with the second iteration, thanks for doing the changes! approved |
@lahodaj This change now passes all automated pre-integration checks. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been no new commits pushed to the
|
* <ul> | ||
* <li>find non-empty packages with the given name returned by | ||
* {@link #getPackageElement(ModuleElement, CharSequence)}, | ||
* where the provided ModuleSymbol is any root module, |
jddarcy
Sep 23, 2020
Member
Does "root module" mean one of the modules in the result of Elements.getAllModuleElements? If so, I suggest making "root module" a link to the method.
Does "root module" mean one of the modules in the result of Elements.getAllModuleElements? If so, I suggest making "root module" a link to the method.
lahodaj
Sep 23, 2020
Author
Contributor
Root module is meant in the java.lang.module sense, i.e. the set of modules that are being compiled. In a new revision, I added a link to the appropriate package javadoc in java.lang.module; and a link to getAllModules for "all modules" in the next point. Does this make sense?
I've generated the javadoc for convenience here:
http://cr.openjdk.java.net/~jlahoda/8236842/docsv2/api/java.compiler/javax/lang/model/util/Elements.html#getTypeElement(java.lang.CharSequence)
http://cr.openjdk.java.net/~jlahoda/8236842/docsv2/api/java.compiler/javax/lang/model/util/Elements.html#getPackageElement(java.lang.CharSequence)
Root module is meant in the java.lang.module sense, i.e. the set of modules that are being compiled. In a new revision, I added a link to the appropriate package javadoc in java.lang.module; and a link to getAllModules for "all modules" in the next point. Does this make sense?
I've generated the javadoc for convenience here:
http://cr.openjdk.java.net/~jlahoda/8236842/docsv2/api/java.compiler/javax/lang/model/util/Elements.html#getTypeElement(java.lang.CharSequence)
http://cr.openjdk.java.net/~jlahoda/8236842/docsv2/api/java.compiler/javax/lang/model/util/Elements.html#getPackageElement(java.lang.CharSequence)
/integrate |
… when cross-compiling with --release Reviewed-by: vromero
Unqualified Elements.getTypeElement(CharSequence) and Elements.getPackageElement(CharSequence) search for elements across all modules in the module graph, and only return a value when they find exactly one element. This is troublesome, as an element (uniquely) visible from a root module may be "hidden" by an element that is not visible from any root module (i.e. is internal to some module that is not in the root module set). The idea proposed here is that these unqualified methods would first look for elements visible from the root modules, and would search the internals of other modules only if nothing would be found in the first round.
The draft of the corresponding CSR is here: https://bugs.openjdk.java.net/browse/JDK-8253168.
/csr JDK-8253168
Progress
Testing
Issue
Reviewers
Download
$ git fetch https://git.openjdk.java.net/jdk pull/200/head:pull/200
$ git checkout pull/200