Skip to content

Comments

Replace Arrays#asList with Collections.singletonList#70

Merged
dkayiwa merged 1 commit intoopenmrs:masterfrom
wikumChamith:SXS-37
May 20, 2025
Merged

Replace Arrays#asList with Collections.singletonList#70
dkayiwa merged 1 commit intoopenmrs:masterfrom
wikumChamith:SXS-37

Conversation

@wikumChamith
Copy link
Member

@wikumChamith wikumChamith commented May 19, 2025

This fixes the com.thoughtworks.xstream.converters.ConversionException: No converter available error when running the 2.x snapshot.

Related ticket: https://openmrs.atlassian.net/browse/SXS-37

@dkayiwa
Copy link
Member

dkayiwa commented May 19, 2025

Did you create a ticket for this?

@wikumChamith
Copy link
Member Author

Did you create a ticket for this?

I couldn't find the JIRA project for this. I am planning to link this with: https://openmrs.atlassian.net/browse/SXS-37

@dkayiwa
Copy link
Member

dkayiwa commented May 19, 2025

On the ticket, fully describe the details that led to this pull request.

@wikumChamith
Copy link
Member Author

On the ticket, fully describe the details that led to this pull request.

I added a comment to ticket: https://openmrs.atlassian.net/browse/SXS-37?focusedCommentId=148941

@dkayiwa
Copy link
Member

dkayiwa commented May 19, 2025

Do you mind also explaining a bit what used to cause this problem and how the singleton fixes it?

@wikumChamith
Copy link
Member Author

Do you mind also explaining a bit what used to cause this problem and how the singleton fixes it?

Arrays.asList() returns an instance of java.util.Arrays$ArrayList which is different from java.util.ArrayList. java.util.Arrays$ArrayList is a private inner class. So when XStream tries to use reflection to serialize fields like modCount, it gets blocked.

private static class ArrayList<E> extends AbstractList<E> implements RandomAccess, Serializable {

Collections.singletonList() returns an instance of: java.util.Collections$SingletonList. This is also a private class, but it doesn't override or expose problematic fields like modCount.

@dkayiwa dkayiwa merged commit 654f418 into openmrs:master May 20, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants