oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.4k stars 1.64k forks source link

[GR-59772] DNS TXT record value parsing error after packaging Native Image #9597

Open yahocen opened 2 months ago

yahocen commented 2 months ago

Describe the issue I am making a small tool to apply for a free SSL certificate through the ACME protocol. I am trying to package it locally using Graalvm. The version I am currently using is Graalvm-community-openjdk-17.0.9+9.1, which includes a feature to obtain Txt resolution record values in DNS through domain names. My code works normally without executing through Native, but the following error occurs after Native. I think this is a bug

Steps to reproduce the issue My code is as follows, please reproduce the error through the following code

public static String getDnsTxtValue(String domain) throws NamingException {
    Hashtable<String, String> env = new Hashtable<>();
    env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
    DirContext dirContext = new InitialDirContext(env);
    //There is an exception here
    Attributes attrs = dirContext.getAttributes(domain, new String[] { "TXT" });
    Attribute txt = attrs.get("TXT");
    NamingEnumeration<?> e = txt.getAll();
    String value = null;
    while (e.hasMore()) {
        value = e.next().toString();
    }
    return value;
}

Describe GraalVM and your environment:

More details

[INFO] Executing: D:\Java\graalvm-community-openjdk-17.0.9+9.1\lib\svm\bin\native-image.exe -cp E:\Workspace\idea\.m2\repository\org\shredzone\acme4j\acme4j-client\3.4.0\acme4j-client-3.4.0.jar;E:\Workspace\idea\.m2\repository\org\bitbucket\b_c\jose4j\0.9.6\jose4j-0.9.6.jar;E:\Workspace\idea\.m2\repository\org\bouncycastle\bcprov-jdk18on\1.78.1\bcprov-jdk18on-1.78.1.jar;E:\Workspace\idea\.m2\repository\org\bouncycastle\bcpkix-jdk18on\1.78.1\bcpkix-jdk18on-1.78.1.jar;E:\Workspace\idea\.m2\repository\org\bouncycastle\bcutil-jdk18on\1.78.1\bcutil-jdk18on-1.78.1.jar;E:\Workspace\idea\.m2\repository\org\slf4j\slf4j-api\2.0.13\slf4j-api-2.0.13.jar;E:\Workspace\idea\.m2\repository\org\slf4j\slf4j-simple\2.0.12\slf4j-simple-2.0.12.jar;E:\Workspace\idea\.m2\repository\dnsjava\dnsjava\3.6.1\dnsjava-3.6.1.jar;E:\Workspace\idea\.m2\repository\cn\hutool\hutool-json\5.8.31\hutool-json-5.8.31.jar;E:\Workspace\idea\.m2\repository\cn\hutool\hutool-core\5.8.31\hutool-core-5.8.31.jar;E:\Workspace\idea\.m2\repository\info\picocli\picocli\4.7.6\picocli-4.7.6.jar;E:\Workspace\idea\.m2\repository\info\picocli\picocli-codegen\4.7.6\picocli-codegen-4.7.6.jar;E:\Workspace\idea\AutoAcme\target\AutoAcme-1.0-SNAPSHOT.jar --no-fallback --enable-url-protocols=https --verbose -H:Class=red.yhc.App -H:Name=AutoAcme
Apply jar:file:///E:/Workspace/idea/AutoAcme/target/AutoAcme-1.0-SNAPSHOT.jar!/META-INF/native-image/picocli-generated/reflect-config.json
Apply jar:file:///E:/Workspace/idea/AutoAcme/target/AutoAcme-1.0-SNAPSHOT.jar!/META-INF/native-image/picocli-generated/resource-config.json
Apply jar:file:///E:/Workspace/idea/AutoAcme/target/AutoAcme-1.0-SNAPSHOT.jar!/META-INF/native-image/picocli-generated/proxy-config.json
Apply jar:file:///D:/Java/graalvm-community-openjdk-17.0.9+9.1/lib/svm/library-support.jar!/META-INF/native-image/com.oracle.svm/thirdparty/native-image.properties
Apply jar:file:///D:/Java/graalvm-community-openjdk-17.0.9+9.1/lib/svm/library-support.jar!/META-INF/native-image/com.oracle.svm/polyglot/native-image.properties
Executing [
'INCLUDE=D:\Visual Studio\Community2022\VC\Tools\MSVC\14.39.33519\include;D:\Visual Studio\Community2022\VC\Tools\MSVC\14.39.33519\ATLMFC\include;D:\Visual Studio\Community2022\VC\Auxiliary\VS\include;D:\Windows Kits\10\include\10.0.22621.0\ucrt;D:\Windows Kits\10\\include\10.0.22621.0\\um;D:\Windows Kits\10\\include\10.0.22621.0\\shared;D:\Windows Kits\10\\include\10.0.22621.0\\winrt;D:\Windows Kits\10\\include\10.0.22621.0\\cppwinrt;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um' \
'LIB=D:\Visual Studio\Community2022\VC\Tools\MSVC\14.39.33519\ATLMFC\lib\x64;D:\Visual Studio\Community2022\VC\Tools\MSVC\14.39.33519\lib\x64;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x64;D:\Windows Kits\10\lib\10.0.22621.0\ucrt\x64;D:\Windows Kits\10\\lib\10.0.22621.0\\um\x64' \
'Path=D:\Visual Studio\Community2022\VC\Tools\MSVC\14.39.33519\bin\HostX64\x64;D:\Visual Studio\Community2022\Common7\IDE\VC\VCPackages;D:\Visual Studio\Community2022\Common7\IDE\CommonExtensions\Microsoft\TestWindow;D:\Visual Studio\Community2022\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;D:\Visual Studio\Community2022\MSBuild\Current\bin\Roslyn;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\x64\;D:\Visual Studio\Community2022\Common7\IDE\CommonExtensions\Microsoft\FSharp\Tools;D:\Visual Studio\Community2022\Team Tools\DiagnosticsHub\Collector;D:\Windows Kits\10\bin\10.0.22621.0\\x64;D:\Windows Kits\10\bin\\x64;D:\Visual Studio\Community2022\\MSBuild\Current\Bin\amd64;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;D:\Visual Studio\Community2022\Common7\IDE\;D:\Visual Studio\Community2022\Common7\Tools\;D:\Python\Python312\Scripts\;D:\Python\Python312\;D:\VMware\VMware Workstation\bin\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\dotnet\;D:\nvm;D:\nodejs;D:\LxRunOffline;D:\Java\graalvm-community-openjdk-17.0.9+9.1\bin;D:\FirefoxPWA\;D:\ffmpeg\ffmpeg-master-latest-win64-gpl\bin;D:\apktool;D:\ADB\platform-tools;D:\Python\Python312;D:\Windows Kits\10\Windows Performance Toolkit\;D:\Java\apache-maven-3.8.2\bin;D:\Visual Studio\Community2022\VC\Tools\MSVC\14.39.33519\bin\Hostx64\x64;D:\Python\Python312\Scripts;D:\Git\cmd;D:\7-Zip;D:\Tencent\??web?????\dll;D:\Rust\.rustup;D:\Rust\.cargo;D:\Rust\.cargo\bin;C:\Users\YahocenMiniPC\AppData\Local\Programs\WingetUI\choco-cli\bin;C:\Users\YahocenMiniPC\AppData\Local\Microsoft\WindowsApps;D:\nvm;D:\nodejs;C:\Users\YahocenMiniPC\.dotnet\tools;C:\Users\YahocenMiniPC\AppData\Local\Programs\Ollama;D:\Visual Studio\Community2022\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;D:\Visual Studio\Community2022\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja;D:\Visual Studio\Community2022\Common7\IDE\VC\Linux\bin\ConnectionManagerExe;D:\Visual Studio\Community2022\VC\vcpkg' \
'TEMP=C:\Users\YAHOCE~1\AppData\Local\Temp' \
USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM=true \
'D:\Java\graalvm-community-openjdk-17.0.9+9.1\bin\java.exe' \
-XX:+UseParallelGC \
-XX:+UnlockExperimentalVMOptions \
-XX:+EnableJVMCI \
-Dtruffle.TrustAllTruffleRuntimeProviders=true \
-Dtruffle.TruffleRuntime=com.oracle.truffle.api.impl.DefaultTruffleRuntime \
-Dgraalvm.ForcePolyglotInvalid=true \
-Dgraalvm.locatorDisabled=true \
-Dsubstratevm.IgnoreGraalVersionCheck=true \
--add-exports=java.base/com.sun.crypto.provider=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.access.foreign=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.event=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.loader=org.graalvm.nativeimage.builder,org.graalvm.truffle \
--add-exports=java.base/jdk.internal.logger=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.misc=org.graalvm.nativeimage.builder,org.graalvm.nativeimage.objectfile,org.graalvm.nativeimage.pointsto \
--add-exports=java.base/jdk.internal.module=jdk.internal.vm.compiler,org.graalvm.nativeimage.base,org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.org.objectweb.asm=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.perf=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.platform=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.ref=org.graalvm.nativeimage.builder,org.graalvm.nativeimage.objectfile \
--add-exports=java.base/jdk.internal.reflect=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.util=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.vm.annotation=org.graalvm.nativeimage.builder \
--add-exports=java.base/jdk.internal.vm=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.invoke.util=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.net=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.nio.ch=org.graalvm.nativeimage.builder,org.graalvm.nativeimage.objectfile \
--add-exports=java.base/sun.reflect.annotation=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.reflect.generics.factory=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.reflect.generics.reflectiveObjects=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.reflect.generics.repository=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.reflect.generics.scope=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.reflect.generics.tree=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.security.jca=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.security.provider=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.security.ssl=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.security.util=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.security.x509=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.text.spi=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.util.calendar=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.util.cldr=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.util.locale.provider=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.util.locale=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.util.resources=org.graalvm.nativeimage.builder \
--add-exports=java.base/sun.util=org.graalvm.nativeimage.builder \
--add-exports=java.management.rmi/com.sun.jmx.remote.internal.rmi=org.graalvm.nativeimage.builder \
--add-exports=java.management.rmi/com.sun.jmx.remote.protocol.rmi=org.graalvm.nativeimage.builder \
--add-exports=java.management/com.sun.jmx.mbeanserver=org.graalvm.nativeimage.builder \
--add-exports=java.management/sun.management=org.graalvm.nativeimage.builder,org.graalvm.nativeimage.pointsto \
--add-exports=java.rmi/sun.rmi.server=org.graalvm.nativeimage.builder \
--add-exports=java.xml.crypto/org.jcp.xml.dsig.internal.dom=org.graalvm.nativeimage.builder \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.aarch64=jdk.internal.vm.compiler,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.objectfile \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.amd64=jdk.internal.vm.compiler,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.objectfile \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code.site=jdk.internal.vm.compiler,org.graalvm.nativeimage.builder \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code.stack=jdk.internal.vm.compiler,org.graalvm.nativeimage.builder \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code=jdk.internal.vm.compiler,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.objectfile,org.graalvm.nativeimage.pointsto \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.common=jdk.internal.vm.compiler,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.pointsto \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot.aarch64=jdk.internal.vm.compiler \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot.amd64=jdk.internal.vm.compiler \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot=jdk.internal.vm.compiler,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.pointsto \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.meta=jdk.internal.vm.compiler,org.graalvm.nativeimage.base,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.objectfile,org.graalvm.nativeimage.pointsto \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.runtime=jdk.internal.vm.compiler,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.pointsto \
--add-exports=jdk.internal.vm.ci/jdk.vm.ci.services=jdk.internal.vm.compiler,org.graalvm.nativeimage.builder \
--add-exports=jdk.jfr/jdk.jfr.events=org.graalvm.nativeimage.builder \
--add-exports=jdk.jfr/jdk.jfr.internal.handlers=org.graalvm.nativeimage.builder \
--add-exports=jdk.jfr/jdk.jfr.internal.jfc=org.graalvm.nativeimage.builder \
--add-exports=jdk.jfr/jdk.jfr.internal=org.graalvm.nativeimage.builder \
--add-exports=jdk.management.agent/jdk.internal.agent=org.graalvm.nativeimage.builder \
--add-exports=jdk.management/com.sun.management.internal=org.graalvm.nativeimage.builder \
-XX:+UseJVMCINativeLibrary \
-Xss10m \
-XX:MaxRAMPercentage=42.244696359775865 \
-XX:GCTimeRatio=19 \
-XX:+ExitOnOutOfMemoryError \
-Djava.awt.headless=true \
'-Dorg.graalvm.vendor=GraalVM Community' \
-Dorg.graalvm.vendorurl=https://www.graalvm.org/ \
'-Dorg.graalvm.vendorversion=GraalVM CE 17.0.9+9.1' \
-Dorg.graalvm.version=23.0.2 \
-Dcom.oracle.graalvm.isaot=true \
-Djava.system.class.loader=com.oracle.svm.hosted.NativeImageSystemClassLoader \
-Xshare:off \
-Djdk.internal.lambda.disableEagerInitialization=true \
-Djdk.internal.lambda.eagerlyInitialize=false \
-Djava.lang.invoke.InnerClassLambdaMetafactory.initializeLambdas=false \
--add-modules=ALL-DEFAULT \
--module-path \
'D:\Java\graalvm-community-openjdk-17.0.9+9.1\lib\truffle\truffle-api.jar;D:\Java\graalvm-community-openjdk-17.0.9+9.1\lib\svm\builder\native-image-base.jar;D:\Java\graalvm-community-openjdk-17.0.9+9.1\lib\svm\builder\objectfile.jar;D:\Java\graalvm-community-openjdk-17.0.9+9.1\lib\svm\builder\pointsto.jar;D:\Java\graalvm-community-openjdk-17.0.9+9.1\lib\svm\builder\svm.jar' \
--module \
org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner \
-imagecp \
'E:\Workspace\idea\.m2\repository\org\shredzone\acme4j\acme4j-client\3.4.0\acme4j-client-3.4.0.jar;E:\Workspace\idea\.m2\repository\org\bitbucket\b_c\jose4j\0.9.6\jose4j-0.9.6.jar;E:\Workspace\idea\.m2\repository\org\bouncycastle\bcprov-jdk18on\1.78.1\bcprov-jdk18on-1.78.1.jar;E:\Workspace\idea\.m2\repository\org\bouncycastle\bcpkix-jdk18on\1.78.1\bcpkix-jdk18on-1.78.1.jar;E:\Workspace\idea\.m2\repository\org\bouncycastle\bcutil-jdk18on\1.78.1\bcutil-jdk18on-1.78.1.jar;E:\Workspace\idea\.m2\repository\org\slf4j\slf4j-api\2.0.13\slf4j-api-2.0.13.jar;E:\Workspace\idea\.m2\repository\org\slf4j\slf4j-simple\2.0.12\slf4j-simple-2.0.12.jar;E:\Workspace\idea\.m2\repository\dnsjava\dnsjava\3.6.1\dnsjava-3.6.1.jar;E:\Workspace\idea\.m2\repository\cn\hutool\hutool-json\5.8.31\hutool-json-5.8.31.jar;E:\Workspace\idea\.m2\repository\cn\hutool\hutool-core\5.8.31\hutool-core-5.8.31.jar;E:\Workspace\idea\.m2\repository\info\picocli\picocli\4.7.6\picocli-4.7.6.jar;E:\Workspace\idea\.m2\repository\info\picocli\picocli-codegen\4.7.6\picocli-codegen-4.7.6.jar;E:\Workspace\idea\AutoAcme\target\AutoAcme-1.0-SNAPSHOT.jar' \
-imagemp \
'D:\Java\graalvm-community-openjdk-17.0.9+9.1\lib\svm\library-support.jar' \
'-H:CLibraryPath=D:\Java\graalvm-community-openjdk-17.0.9+9.1\lib\svm\clibraries\windows-amd64' \
'-H:Path=E:\Workspace\idea\AutoAcme\target' \
'-H:ReflectionConfigurationResources@jar:file:///E:/Workspace/idea/AutoAcme/target/AutoAcme-1.0-SNAPSHOT.jar!/META-INF/native-image/picocli-generated/reflect-config.json=META-INF/native-image/picocli-generated/reflect-config.json' \
'-H:ResourceConfigurationResources@jar:file:///E:/Workspace/idea/AutoAcme/target/AutoAcme-1.0-SNAPSHOT.jar!/META-INF/native-image/picocli-generated/resource-config.json=META-INF/native-image/picocli-generated/resource-config.json' \
'-H:DynamicProxyConfigurationResources@jar:file:///E:/Workspace/idea/AutoAcme/target/AutoAcme-1.0-SNAPSHOT.jar!/META-INF/native-image/picocli-generated/proxy-config.json=META-INF/native-image/picocli-generated/proxy-config.json' \
-H:FallbackThreshold=0 \
-H:EnableURLProtocols=https \
-H:Class=red.yhc.App \
-H:Name=AutoAcme \
'-H:Features@jar:file:///D:/Java/graalvm-community-openjdk-17.0.9+9.1/lib/svm/library-support.jar!/META-INF/native-image/com.oracle.svm/thirdparty/native-image.properties=com.oracle.svm.thirdparty.gson.GsonFeature' \
'-H:Features@jar:file:///D:/Java/graalvm-community-openjdk-17.0.9+9.1/lib/svm/library-support.jar!/META-INF/native-image/com.oracle.svm/polyglot/native-image.properties=com.oracle.svm.polyglot.groovy.GroovyIndyInterfaceFeature,com.oracle.svm.polyglot.scala.ScalaFeature'
========================================================================================================================
GraalVM Native Image: Generating 'AutoAcme' (executable)...
========================================================================================================================
For detailed information and explanations on the build output, visit:
https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md
------------------------------------------------------------------------------------------------------------------------
[1/8] Initializing...                                                                                    (5.0s @ 0.23GB)
 Java version: 17.0.9+9, vendor version: GraalVM CE 17.0.9+9.1
 Graal compiler: optimization level: 2, target machine: x86-64-v3
 C compiler: cl.exe (microsoft, x64, 19.39.33523)
 Garbage collector: Serial GC (max heap size: 80% of RAM)
[2/8] Performing analysis...  [******]                                                                  (16.6s @ 1.91GB)
   9,820 (87.58%) of 11,212 types reachable
  17,213 (65.94%) of 26,105 fields reachable
  49,545 (58.62%) of 84,520 methods reachable
   2,830 types,   114 fields, and 1,933 methods registered for reflection
      80 types,    71 fields, and    67 methods registered for JNI access
       4 native libraries: crypt32, ncrypt, version, winhttp
[3/8] Building universe...                                                                               (2.3s @ 1.76GB)
[4/8] Parsing methods...      [*]                                                                        (1.6s @ 1.55GB)
[5/8] Inlining methods...     [***]                                                                      (0.9s @ 1.66GB)
[6/8] Compiling methods...    [****]                                                                    (12.2s @ 0.97GB)
[7/8] Layouting methods...    [**]                                                                       (2.7s @ 1.64GB)
[8/8] Creating image...       [**]                                                                       (3.1s @ 1.13GB)
  25.85MB (51.96%) for code area:    32,027 compilation units
  23.57MB (47.39%) for image heap:  267,825 objects and 70 resources
 332.80kB ( 0.65%) for other data
  49.75MB in total
------------------------------------------------------------------------------------------------------------------------
Top 10 origins of code area:                                Top 10 object types in image heap:
  12.29MB java.base                                            5.46MB byte[] for code metadata
   3.71MB java.xml                                             2.53MB java.lang.String
   2.97MB bcprov-jdk18on-1.78.1.jar                            2.46MB byte[] for general heap data
   1.31MB java.net.http                                        2.34MB java.lang.Class
   1.15MB svm.jar (Native Image)                               1.94MB byte[] for java.lang.String
 932.88kB picocli-4.7.6.jar                                  843.91kB com.oracle.svm.core.hub.DynamicHubCompanion
 433.22kB hutool-core-5.8.31.jar                             752.29kB byte[] for embedded resources
 354.45kB java.rmi                                           547.69kB java.util.HashMap$Node
 353.91kB jdk.crypto.ec                                      536.88kB java.lang.String[]
 296.29kB AutoAcme-1.0-SNAPSHOT.jar                          513.00kB int[][]
   1.89MB for 26 more packages                                 4.68MB for 2205 more object types
------------------------------------------------------------------------------------------------------------------------
Recommendations:
 HEAP: Set max heap for improved and more predictable memory usage.
 CPU:  Enable more CPU features with '-march=native' for improved performance.
------------------------------------------------------------------------------------------------------------------------
                       4.7s (10.4% of total time) in 86 GCs | Peak RSS: 3.65GB | CPU load: 10.70
------------------------------------------------------------------------------------------------------------------------
Produced artifacts:
 E:\Workspace\idea\AutoAcme\target\AutoAcme.exe (executable)
========================================================================================================================
Finished generating 'AutoAcme' in 44.9s.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  51.609 s
[INFO] Finished at: 2024-09-02T17:42:53+08:00
[INFO] ------------------------------------------------------------------------

Add any other information about the problem here. Especially important are stack traces or log output. Feel free to link to gists or to screenshots if necessary.

Caused by: java.lang.NullPointerException
    at java.base@17.0.9/sun.net.dns.ResolverConfigurationImpl.stringToList(ResolverConfigurationImpl.java:69)
    at java.base@17.0.9/sun.net.dns.ResolverConfigurationImpl.loadConfig(ResolverConfigurationImpl.java:136)
    at java.base@17.0.9/sun.net.dns.ResolverConfigurationImpl.nameservers(ResolverConfigurationImpl.java:159)
    at jdk.naming.dns@17.0.9/com.sun.jndi.dns.DnsContextFactory.serversForUrls(DnsContextFactory.java:149)
    at jdk.naming.dns@17.0.9/com.sun.jndi.dns.DnsContextFactory.getContext(DnsContextFactory.java:81)
    at jdk.naming.dns@17.0.9/com.sun.jndi.dns.DnsContextFactory.urlToContext(DnsContextFactory.java:120)
    at jdk.naming.dns@17.0.9/com.sun.jndi.dns.DnsContextFactory.getInitialContext(DnsContextFactory.java:64)
    at java.naming@17.0.9/javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:732)
    at java.naming@17.0.9/javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:305)
    at java.naming@17.0.9/javax.naming.InitialContext.init(InitialContext.java:236)
    at java.naming@17.0.9/javax.naming.InitialContext.<init>(InitialContext.java:208)
    at java.naming@17.0.9/javax.naming.directory.InitialDirContext.<init>(InitialDirContext.java:130)
    at red.yhc.util.DomainUtil.getDnsTxtValue(DomainUtil.java:33)
    at red.yhc.acme.AcmeOper.dnsChallenge(AcmeOper.java:303)
yahocen commented 2 months ago

Complete Java classes for debugging purposes 🙏

import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import java.util.Hashtable;

public class Test {

    public static String getDnsTxtValue(String domain) throws NamingException {
        Hashtable<String, String> env = new Hashtable<>();
        env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
        DirContext dirContext = new InitialDirContext(env);
        //There is an exception here
        Attributes attrs = dirContext.getAttributes(domain, new String[] { "TXT" });
        Attribute txt = attrs.get("TXT");
        NamingEnumeration<?> e = txt.getAll();
        String value = null;
        while (e.hasMore()) {
            value = e.next().toString();
        }
        return value;
    }

    public static void main(String[] args) throws NamingException {
        //The record type here is TXT
        System.out.println(getDnsTxtValue("_acme-challenge.example.com"));
    }

}
oubidar-Abderrahim commented 2 months ago

Thank you, we'll take a look into this when possible

yahocen commented 2 months ago

Before fixing this issue, you can use nslookup and Process to solve it

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Test {

    public static List<String> getTXTRecord(String domain) throws IOException, InterruptedException {
        List<String> txtRecords = new ArrayList<>();
        // 使用 ProcessBuilder 运行 nslookup 命令
        var pb = new ProcessBuilder("nslookup", "-query=TXT", domain);
        var process = pb.start();
        // 读取命令输出
        try (var reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
            String line;
            boolean recordFound = false;
            while ((line = reader.readLine()) != null) {
                // 检查是否为TXT记录
                if (line.contains("text =")) {
                    recordFound = true;
                }
                // 获取TXT记录值部分
                if (recordFound && line.trim().startsWith("\"")) {
                    txtRecords.add(line.trim().replace("\"", ""));
                }
            }
        }
        process.waitFor();
        return txtRecords;
    }

    public static void main(String[] args) throws IOException, InterruptedException {
        //The record type here is TXT
        // 示例域名
        String domain = "_acme-challenge.example.com";
        List<String> txtRecords = getTXTRecord(domain);
        // 输出TXT记录值
        txtRecords.forEach(record -> System.out.println("TXT Record: " + record));
    }

}
oubidar-Abderrahim commented 2 months ago

I tested the code from here: https://github.com/oracle/graal/issues/9597#issuecomment-2324325603 it didn't run correctly as a java code

>java Test
Exception in thread "main" javax.naming.NameNotFoundException: DNS name not found [response code 3]; remaining name '_acme-challenge.example.com'
        at jdk.naming.dns/com.sun.jndi.dns.DnsClient.checkResponseCode(DnsClient.java:659)
        at jdk.naming.dns/com.sun.jndi.dns.DnsClient.isMatchResponse(DnsClient.java:577)
        at jdk.naming.dns/com.sun.jndi.dns.DnsClient.doUdpQuery(DnsClient.java:429)
        at jdk.naming.dns/com.sun.jndi.dns.DnsClient.query(DnsClient.java:214)
        at jdk.naming.dns/com.sun.jndi.dns.Resolver.query(Resolver.java:81)
        at jdk.naming.dns/com.sun.jndi.dns.DnsContext.c_getAttributes(DnsContext.java:434)
        at java.naming/com.sun.jndi.toolkit.ctx.ComponentDirContext.p_getAttributes(ComponentDirContext.java:235)
        at java.naming/com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:141)
        at java.naming/com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:129)
        at java.naming/javax.naming.directory.InitialDirContext.getAttributes(InitialDirContext.java:171)
        at Test.getDnsTxtValue(Test.java:16)
        at Test.main(Test.java:28)

Is there something missing in the code?

yahocen commented 2 months ago

I tested the code from here: #9597 (comment)我从这里测试了代码: #9597 (comment) it didn't run correctly as a java code它不能作为 Java 代码正确运行

>java Test
Exception in thread "main" javax.naming.NameNotFoundException: DNS name not found [response code 3]; remaining name '_acme-challenge.example.com'
        at jdk.naming.dns/com.sun.jndi.dns.DnsClient.checkResponseCode(DnsClient.java:659)
        at jdk.naming.dns/com.sun.jndi.dns.DnsClient.isMatchResponse(DnsClient.java:577)
        at jdk.naming.dns/com.sun.jndi.dns.DnsClient.doUdpQuery(DnsClient.java:429)
        at jdk.naming.dns/com.sun.jndi.dns.DnsClient.query(DnsClient.java:214)
        at jdk.naming.dns/com.sun.jndi.dns.Resolver.query(Resolver.java:81)
        at jdk.naming.dns/com.sun.jndi.dns.DnsContext.c_getAttributes(DnsContext.java:434)
        at java.naming/com.sun.jndi.toolkit.ctx.ComponentDirContext.p_getAttributes(ComponentDirContext.java:235)
        at java.naming/com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:141)
        at java.naming/com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:129)
        at java.naming/javax.naming.directory.InitialDirContext.getAttributes(InitialDirContext.java:171)
        at Test.getDnsTxtValue(Test.java:16)
        at Test.main(Test.java:28)

Is there something missing in the code?代码中是否缺少什么?

Hi, I'm glad there's been progress. In fact, the _acme-challenge.example.com in the code is an example domain and doesn't actually exist. I'm sorry for any inconvenience caused. Please remove the _acme-challenge section and replace it with example.com

yahocen commented 2 months ago

I tested the code from here: #9597 (comment)我从这里测试了代码: #9597 (comment) it didn't run correctly as a java code它不能作为 Java 代码正确运行

>java Test
Exception in thread "main" javax.naming.NameNotFoundException: DNS name not found [response code 3]; remaining name '_acme-challenge.example.com'
        at jdk.naming.dns/com.sun.jndi.dns.DnsClient.checkResponseCode(DnsClient.java:659)
        at jdk.naming.dns/com.sun.jndi.dns.DnsClient.isMatchResponse(DnsClient.java:577)
        at jdk.naming.dns/com.sun.jndi.dns.DnsClient.doUdpQuery(DnsClient.java:429)
        at jdk.naming.dns/com.sun.jndi.dns.DnsClient.query(DnsClient.java:214)
        at jdk.naming.dns/com.sun.jndi.dns.Resolver.query(Resolver.java:81)
        at jdk.naming.dns/com.sun.jndi.dns.DnsContext.c_getAttributes(DnsContext.java:434)
        at java.naming/com.sun.jndi.toolkit.ctx.ComponentDirContext.p_getAttributes(ComponentDirContext.java:235)
        at java.naming/com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:141)
        at java.naming/com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:129)
        at java.naming/javax.naming.directory.InitialDirContext.getAttributes(InitialDirContext.java:171)
        at Test.getDnsTxtValue(Test.java:16)
        at Test.main(Test.java:28)

Is there something missing in the code?代码中是否缺少什么?

Hi, I'm glad there's been progress. In fact, the _acme-challenge.example.com in the code is an example domain and doesn't actually exist. I'm sorry for any inconvenience caused. Please remove the _acme-challenge section and replace it with example.com嗨,我很高兴取得了进展。事实上,代码中的 _acme-challenge.example.com 是一个示例域,实际上并不存在。对于给您带来的任何不便,我深表歉意。请删除 _acme-challenge 部分并将其替换为 example.com

public static void main(String[] args) throws NamingException {
    //The record type here is TXT
    System.out.println(getDnsTxtValue("example.com"));
}