mbien commented on code in PR #4672:
URL: https://github.com/apache/netbeans/pull/4672#discussion_r977032122
##########
java/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/Utilities.java:
##########
@@ -1083,7 +1083,7 @@ public synchronized ClasspathInfo createUniversalCPInfo()
{
final JavaPlatformManager man = JavaPlatformManager.getDefault();
if (select.getSpecification().getVersion() != null) {
for (JavaPlatform p :
JavaPlatformManager.getDefault().getInstalledPlatforms()) {
- if (!"j2se".equals(p.getSpecification().getName()) ||
p.getSpecification().getVersion() == null) continue;
+ if (!p.isValid() ||
!"j2se".equals(p.getSpecification().getName()) ||
p.getSpecification().getVersion() == null) continue;
if
(p.getSpecification().getVersion().compareTo(select.getSpecification().getVersion())
> 0) {
select = p;
}
Review Comment:
the fix makes sense. But I believe this whole section needs some work.
E.g if the default platform has no spec version, it would simply select the
default platform without searching further?
how about:
```java
final JavaPlatformManager man = JavaPlatformManager.getDefault();
JavaPlatform select = Stream.of(man.getInstalledPlatforms())
.filter(JavaPlatform::isValid)
.filter((p) ->
"j2se".equals(p.getSpecification().getName()))
.filter((p) -> p.getSpecification().getVersion() != null)
.max((p1, p2) ->
p1.getSpecification().getVersion().compareTo(p2.getSpecification().getVersion()))
.orElse(JavaPlatform.getDefault());
```
edit: maybe we should even add a cap to not pick a version which goes beyond
(nb-)javac. Getting the feature version of (nb-javac) is easy:
`SourceVersion.latest().ordinal()`. The SpecificationVersion is just a bit
limited at the moment.
```java
SpecificationVersion maxVersion = new
SpecificationVersion(SourceVersion.latest().ordinal()+".99");
...
.filter((p) -> p.getSpecification().getVersion().compareTo(maxVersion) < 0)
```
this would filter out JDK 20 for example on master, but pick 19
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists