1

I am using JDK 15.0.1 and try to save a record. I got an error in the microstream code. The exception in the statement if (declaringClass.isRecord()) is thrown with text can't get field offset on a record (preview):.

In the documentation, it is stated that records are supported since JDK 14 (see 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);
    }

I use the following version of microstream

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

Did I do something wrong?

Sincerely

Marcel Baumann
  • 181
  • 1
  • 6

2 Answers2

2

thank you for your interest in microstream. Unfortunately, I can't come to the place where the problem is from the description of the problem. The code that is in the description comes from the jdk class Unsafe.java. Since I can't reproduce your problem yet, I quickly did a small test project in github, where the basic test for Records is in 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());

    }

Records are still only preview function, so it is necessary to enable it. For example in 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>

Zdenek Jonas
  • 121
  • 7
  • Hello Jonas, Thanks for the example. I now can better describe the problem thanks to your pom file. As stated in my post I use JDK 15.0.1 and the example provided crashes. I also tested with a simple record as in your test under JDK 15.0.1 and it also crashed. Once I moved backed to JDK 14.0.2 both tests run successfully. Therefore we can probably state that microstream supports for records is probably broken in JDK 15.0.1. Thanks for the support and we can hope that the glitch is fixed in a next release. For the moment I rolled my project back to 14.0.2. Cheers – Marcel Baumann Nov 11 '20 at 16:08
  • Another precision, I am using Oracle JDK 15.0.1 and Oracle JDK 14.0.2 – Marcel Baumann Nov 11 '20 at 16:30
  • 1
    Hello Marcel, ok, this was important. I have made this test on openJDK. With Oracle JDK i can simulate this problem too. – Zdenek Jonas Nov 12 '20 at 07:48
  • Hello Jonas, I can work the next weeks with the Oracle JDK 14.0.2 and continue development with MicroStream. I hope an updated version of MicroStream will be release soon. Cheers – Marcel Baumann Nov 13 '20 at 12:58
  • 1
    Hello Marcel, i have created an issue in our system and this issue will be planned into next release. But this is still JDK preview feature, it can be still changed. – Zdenek Jonas Nov 15 '20 at 21:48
1

Newer versions of Microstream have a workaround for record (for example version 6)

Due to reflection restrictions of records introduced in Java 15 an export has to be added to the VM parameters:

--add-exports java.base/jdk.internal.misc=ALL_UNNAMED

See also Microstream FAQ

Marcel Baumann
  • 181
  • 1
  • 6