[
https://issues.apache.org/jira/browse/LUCENE-10339?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17465582#comment-17465582
]
Tomoko Uchida commented on LUCENE-10339:
----------------------------------------
I run a little sanity check code. Although the IDE complains that the "require"
directives should be added, it seems to work without any additional
modification on module-info for me.
{code:java}
// empty module-info.java
module modtest {}
// test module to check if the reflective access is allowed
package modtest;
import java.lang.reflect.Method;
public class Main {
public static void main(String[] args) {
try {
// copied snippet from RamUsageEstimator
//
https://github.com/apache/lucene/blob/d928c47d6e114303f09449514a29161f626ab7dd/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java#L119
// this succeeds
Class<?> beanClazz =
Class.forName("com.sun.management.HotSpotDiagnosticMXBean");
final Method getVMOptionMethod = beanClazz.getMethod("getVMOption",
String.class);
final Object hotSpotBean =
Class.forName("java.lang.management.ManagementFactory")
.getMethod("getPlatformMXBean", Class.class)
.invoke(null, beanClazz);
final Object vmOption = getVMOptionMethod.invoke(hotSpotBean,
"UseCompressedOops");
boolean compressedOops =
Boolean.parseBoolean(
vmOption.getClass().getMethod("getValue").invoke(vmOption).toString());
System.out.println("Compressed OOPs enabled: " + compressedOops);
// this fails if "require jdk.unsupported" is not declared
System.out.println(Class.forName("sun.misc.Unsafe").getName());
} catch (Exception e) {
e.printStackTrace();
}
}
}
{code}
Unlike {{{}sun.misc.Unsafe{}}}, {{com.sun.management.HotSpotDiagnosticMXBean}}
can be accessed without "require" directive on OpenJDK 11 on Linux platform.
{code:java}
$ java --version
openjdk 11.0.10 2021-01-19
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.10+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.10+9, mixed mode)
$ java --module-path modules -m modtest/modtest.Main
Compressed OOPs enabled: true // OK
java.lang.ClassNotFoundException: sun.misc.Unsafe // Failed
at
java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
{code}
I tried to find documentation but couldn't locate it. Does this result indicate
that reflective access to "jdk.management" is allowed by default?
> Add require derective for jdk.management to core's module descriptor.
> ---------------------------------------------------------------------
>
> Key: LUCENE-10339
> URL: https://issues.apache.org/jira/browse/LUCENE-10339
> Project: Lucene - Core
> Issue Type: Sub-task
> Reporter: Tomoko Uchida
> Priority: Major
> Attachments: Screenshot from 2021-12-25 18-04-55.png, Screenshot from
> 2021-12-25 20-11-38.png
>
> Time Spent: 10m
> Remaining Estimate: 0h
>
> IntelliJ IDEA warns as follows in o.a.l.u.RamUsageEstimator.
> !Screenshot from 2021-12-25 18-04-55.png!
> !Screenshot from 2021-12-25 20-11-38.png!
> This means we would need "require" or "require static" directive(s) in core's
> module descriptor to make RamUsageEstimator correctly work.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]