pkl icon indicating copy to clipboard operation
pkl copied to clipboard

Unsafe warning on 0.28.2 and Java 24

Open ShiftSad opened this issue 6 months ago • 1 comments

I'm on pkl-config-java-all version 0.28.2, Pkl 0.28.2 (Windows 10.0, native) and OpenJDK 24.0.1

Warning:

WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::objectFieldOffset has been called by com.oracle.truffle.api.nodes.NodeClassImpl$NodeFieldData (file:/C:/Users/---/.gradle/caches/modules-2/files-2.1/org.pkl-lang/pkl-config-java-all/0.28.2/1cead8c0419840532c33b53da3295b56853140f1/pkl-config-java-all-0.28.2.jar)
WARNING: Please consider reporting this to the maintainers of class com.oracle.truffle.api.nodes.NodeClassImpl$NodeFieldData
WARNING: sun.misc.Unsafe::objectFieldOffset will be removed in a future release

My configuration loader class has these two methods for acessing data, and they seem related to the warning being thrown.

    /**
     * Returns the child node with the given unqualified name.
     * Allows for nested keys using dot notation (e.g., "parent.child").
     *
     * @throws NoSuchChildException if a child with the given name does not exist
     */
    public Config get(String key) {
        String[] parts = key.split("\\.");
        Config current = config;
        for (String part : parts) {
            current = current.get(part);
        }
        return current;
    }

    /**
     * Returns the child node with the given unqualified name and converts it to the specified type.
     *
     * @throws NoSuchChildException if a child with the given name does not exist
     * @throws ConversionException if the value cannot be converted to the given type
     */
    public <T> T get(String key, Class<T> type) {
        return get(key).as(type);
    }

I've got it running the test bellow, it passes but throws warnig.

    @BeforeEach
    void setUp() throws IOException {
        Files.createDirectories(tempDir);

        tempConfigFile = tempDir.resolve("my-app-test.pkl");
        Files.writeString(tempConfigFile,
                "app { \n" +
                        "  name = \"TestApp\" \n" +
                        "  version = 1.0 \n" +
                        "  enabled = true \n" +
                        "}\n" +
                        "server {\n" +
                        "  port = 8080\n" +
                        "  timeout = 5000\n" +
                        "}"
        );

        tempDefaultConfigFile = tempDir.resolve(TEST_RESOURCE_CONFIG);
        Files.deleteIfExists(tempDefaultConfigFile);
    }

    @Test
    @DisplayName("Should load an existing configuration file successfully")
    void testLoadExistingFile_success() throws IOException {
        ConfigurationLoader loader = new ConfigurationLoader(tempConfigFile.toString());
        assertNotNull(loader);
        assertEquals("TestApp", loader.get("app.name", String.class));
        assertEquals(1.0, loader.get("app.version", Double.class));
        assertTrue(loader.get("app.enabled", Boolean.class));
    }

ShiftSad avatar Jun 25 '25 02:06 ShiftSad

We'll update graalvm/truffle for the 0.30 release. So, hopefully this will be fixed.

stackoverflow avatar Jun 30 '25 09:06 stackoverflow