-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can't get field offset on a record class using quarkus-junit5 #40148
Comments
This has long been a thorn in our side unfortunately... It's one that @holly-cummins was looking into, but it seems very very complicated |
Yes, I think this is a duplicate of ... actually, we have several issues in this area. I got quite far with the fix and then got a bit stuck between a number of undesirable options - but still looking at it. |
Thanks for the update @holly-cummins! |
@Eternal-night-blip, there is a workaround for this issue, which is to use a version of Java below 16. Obviously, that causes all sorts of other issues, though. The minimum version of Java for recent Quarkus releases is 17, so you might even need to go to a lower version of Quarkus. So it's definitely not a nice workaround. |
@holly-cummins,well, I hope you fix this bug someday,good luck to you. So for now I just have to manually build the parametrized tests for myself. |
May be fixed by #40601 |
If someone has the same problem, you can make a record |
Hi there, any update on this ? (cc @holly-cummins) It seems moving from xStream to another marshaller fixes the problem but its not possible for me in that case. |
Hi @cyrilcolinet, we're waiting for a release of JUnit 5.11, or a backport of junit-team/junit5#3820 to JUnit 5.10.3. Once that's done, we can merge #40906, which should fix this issue. |
Perfect. If this issue is still not fixed, you might need to instantiate a "custom" xStream converter which handles the records perfectly. This is the code converter: import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import java.lang.reflect.Constructor;
import java.lang.reflect.RecordComponent;
import java.util.Arrays;
public class RecordConverter implements Converter {
@Override
public boolean canConvert(Class type) {
return type.isRecord();
}
@Override
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
Class<?> recordClass = source.getClass();
RecordComponent[] components = recordClass.getRecordComponents();
try {
for (RecordComponent component : components) {
writer.startNode(component.getName());
Object value = component.getAccessor().invoke(source);
if (value != null) {
context.convertAnother(value);
}
writer.endNode();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
Class<?> recordClass = context.getRequiredType();
RecordComponent[] components = recordClass.getRecordComponents();
Object[] values = new Object[components.length];
try {
int i = 0;
while (reader.hasMoreChildren()) {
reader.moveDown();
for (RecordComponent component : components) {
if (component.getName().equals(reader.getNodeName())) {
values[i] = context.convertAnother(null, component.getType());
i++;
break;
}
}
reader.moveUp();
}
Constructor<?> constructor = recordClass.getDeclaredConstructor(
Arrays.stream(components).map(RecordComponent::getType).toArray(Class[]::new)
);
return constructor.newInstance(values);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
} and register it via The made me continue |
We are running into a similar issue with Quarkus 3.13.0, which switched the serializer as outlined in the earlier comments of this thread. In our case, the class where This worked fine with Quarkus v3.12.3, but fails with v3.13.0. Accessing methods of the
Complete Stacktrace
The fix is to make the |
…meterizedTest` See quarkusio/quarkus#40148 (comment) Signed-off-by: nscuro <nscuro@protonmail.com>
@nscuro, do you mind raising a new defect for the issue you're seeing in 3.13.0? |
@holly-cummins the newest version 3.13.0 brakes everything even with |
Could someone provide a small reproducer for the issue? |
@dmlloyd FYI ^ |
@yk-littlepay, is your code the same code as what @Eternal-night-blip provided in the initial description, or is your code slightly different? Was your code working with 3.12.x, or has it always been broken? There are some scenarios that used to work that have stopped working with 3.13.0, for example, #42006 and #42098. If your code used to work before 3.13.0, I think it probably needs a new issue, or a comment on #42098 or #42006. |
@holly-cummins the code works fine with 3.12.3 and |
Thanks, @yk-littlepay. That definitely sounds like a new problem, then. The scenario being tracked by this original issue didn't work with 3.12.3, but now does work with 3.13.0. The serialization changes which fixed the original problem broke some other things. Could you please raise a new issue? As @gsmet says, if you can provide a reproducer, that's really helpful. |
@holly-cummins & @gsmet in a nutshell "Records that contain Enum are still unsupported with @ParameterizedTest even with Serializable in 3.13.0". See the link immediately after your message, there is also a very simple project with a reproducible error. |
Describe the bug
I am new to Quarkus and want to hand on effective java test.
When I used the parameterization test on the ItemWait class by quarkus-junit5:3.9.3, relied XStream library reported an error as below. how can I do, can I replace Xstream? Note that I donnot want to replace the record Class with a regular class Class for ItemDetail.
Version and Build tool
quarkus 3.9.3
maven auto controlled by quarkus
Error Message
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 org.todo.domain.item.ItemDetail.name
class : org.todo.domain.item.ItemDetail
required-type : org.todo.domain.item.ItemDetail
converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path : /org.todo.domain.item.ItemWait/detail/name
line number : 6
class[1] : org.todo.domain.item.ItemWait
required-type[1] : org.todo.domain.item.ItemWait
version : 1.4.20
Code
The text was updated successfully, but these errors were encountered: