question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A @QuarkusTest with a ParameterResolver that return a java record, throws an exception

See original GitHub issue

Describe the bug

During a QuarkuTest, when using a junit “ParameterResolver” that return a java record with at least one field, xstream return this error:

com.thoughtworks.xstream.converters.ConversionException: 
---- Debugging information ----
cause-exception     : java.lang.UnsupportedOperationException
cause-message       : can't get field offset on a record class: private final java.lang.String com.example.TestRecord.test
class               : com.example.TestRecord
required-type       : com.example.TestRecord
converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path                : /com.example.TestRecord/test
line number         : 2
version             : 1.4.15
-------------------------------

The problem in quarkus is at io.quarkus.test.junit.internal.XStreamDeepClone.doClone(XStreamDeepClone.java:49)

As far as I understand, this class use xstream to just create a copy of the object (the java record) in the Quarkus ClassLoader. If it’s the only usage, i think we can use another library that support records (and maybe use json instead of XML).

what do you think?

The cause is:

java.lang.UnsupportedOperationException: can't get field offset on a record class: private final java.lang.String com.example.TestRecord.test
	at jdk.unsupported/sun.misc.Unsafe.objectFieldOffset(Unsafe.java:648)
	at com.thoughtworks.xstream.converters.reflection.SunUnsafeReflectionProvider.getFieldOffset(SunUnsafeReflectionProvider.java:105)

To Reproduce

It’s very simple.

1- Create a Java record, with at least one field record TestRecord(String test)

2- Create a ParameterResolver that return the record new TestRecord("my test")

3- Create a quarkus test that use that ParameterResolver eg:

@QuarkusTest
@ExtendWith(TestRecordResolver.class)
public class QuarkusRecordTest {
  @Test
  public void test(TestRecord record) {
    assert record != null;
  }

}

Environment:

Output of uname -a or ver

Darwin MacBookPro.lan 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:06:51 PST 2021; root:xnu-7195.81.3~1/RELEASE_ARM64_T8101 arm64

Output of java -version

openjdk 16 2021-03-16 OpenJDK Runtime Environment AdoptOpenJDK (build 16+36) OpenJDK 64-Bit Server VM AdoptOpenJDK (build 16+36, mixed mode, sharing)

Quarkus version or git rev

Quarkus 1.12.2.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Maven 3.6.3

Additional context

I reproduced it in a new empty project. I can post it, if need, but it’s super simple.

This occurs from java 15, for this reason https://mail.openjdk.java.net/pipermail/amber-dev/2020-June/006241.html https://medium.com/@atdsqdjyfkyziqkezu/java-15-breaks-deserialization-of-records-902fcc81253d

Complete stacktrace.txt

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:17 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
stuartwdouglascommented, Mar 23, 2021

We should look at adding some hooks into JUnit so we no longer require this copying.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Junit 5 - No ParameterResolver registered for parameter
ParameterResolutionException while working with Junit 4. Currently it's Junit 5 and I googled it to get some sort of idea but can not...
Read more >
Issue with running @QuarkusTest - Google Groups
I am using JDK 11, Quarkus 2.3. While using @QuarkusTest I am facing RunTimeException as shown below: java.lang.RuntimeException: java.lang.
Read more >
Jupiter | MIPS ISA CSL Course Project - kandi
Jupiter is a Java library. Jupiter has no bugs, it has no vulnerabilities and it has low support. However Jupiter build file is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found