首页 > 解决方案 > 微流是否已经支持 JDK 15 - 记录问题

问题描述

我正在使用 JDK 15.0.1 并尝试保存记录。我在微流代码中遇到错误。语句if (declaringClass.isRecord())中的异常抛出 text can't get field offset on a record (preview):

在文档中,声明自 JDK 14 起支持记录(请参阅https://manual.docs.microstream.one/data-store/faq/java-features#can-microstream-handle-records)。

        if (f == null) {
            throw new NullPointerException();
        }
        Class<?> declaringClass = f.getDeclaringClass();
        if (declaringClass.isHidden()) {
            throw new UnsupportedOperationException("can't get field offset on a hidden class: " + f);
        }
        if (declaringClass.isRecord()) {
            throw new UnsupportedOperationException("can't get field offset on a record (preview): " + f);
        }
        return theInternalUnsafe.objectFieldOffset(f);
    }

我使用以下版本的微流

implementation 'one.microstream:storage.embedded:04.00.00-MS-GA'

我做错什么了吗?

真挚地

标签: microstream

解决方案


感谢您对微流的关注。不幸的是,我无法从问题的描述中得出问题所在的地方。描述中的代码来自 jdk 类Unsafe.java。由于我还不能重现你的问题,所以我很快在 github 上做了一个小测试项目,其中 Records 的基本测试是用 Java 进行的。 https://github.com/johny2000uwb/microstream-records

public record PersonRecord(String firstName, String lastName) {

}
    @Test
    public void saveRecordTest() {
        PersonRecord personRecord = new PersonRecord("Maria", "Lukasova");

        EmbeddedStorageManager storage = EmbeddedStorage.start(personRecord, location);
        storage.shutdown();

        PersonRecord secondRecord = new PersonRecord("Kamila", "Pazourkova");
        storage = EmbeddedStorage.start(secondRecord, location);

        Assertions.assertEquals("Maria", secondRecord.firstName());

    }

记录仍然只是预览功能,所以需要启用它。例如在 Maven 中:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <release>14</release> <!-- <release>13/14/15</release> -->
                    <compilerArgs>--enable-preview</compilerArgs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
                <configuration>
                    <argLine>--enable-preview</argLine>
                </configuration>
            </plugin>
        </plugins>
    </build>


推荐阅读