Skip to content
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

BUG: failing test_hierharchy_arraylist with jdk>=21 #736

Open
h-vetinari opened this issue Nov 19, 2024 · 2 comments
Open

BUG: failing test_hierharchy_arraylist with jdk>=21 #736

h-vetinari opened this issue Nov 19, 2024 · 2 comments
Labels

Comments

@h-vetinari
Copy link

When building pyjnius 1.6.1 against newer openjdk (21, 22) in conda-forge, things compile and run fine, with the exception of one test failure:

=================================== FAILURES ===================================
____________________ ReflectTest.test_hierharchy_arraylist _____________________

self = <test_reflect.ReflectTest testMethod=test_hierharchy_arraylist>

    def test_hierharchy_arraylist(self):
        d = identify_hierarchy_dict(find_javaclass("java.util.ArrayList"), 0, True)
        self.assertContains(d, "java.util.ArrayList")# concrete
        self.assertContains(d, "java.util.AbstractCollection")# superclass
        self.assertContains(d, "java.util.Collection")# interface
        self.assertContains(d, "java.lang.Iterable")# interface
        self.assertContains(d, "java.lang.Object")# root
        maxLevel = max(d.values())
>       self.assertEqual(d["java.lang.Object"], maxLevel)
E       AssertionError: 3 != 4

tests/test_reflect.py:38: AssertionError
=========================== short test summary info ============================
FAILED tests/test_reflect.py::ReflectTest::test_hierharchy_arraylist - AssertionError: 3 != 4
======================== 1 failed, 164 passed in 0.94s =========================

It seems all the expected hierarchy levels are still there, but either the hierarchy itself changed for real (meaning the test expectation is wrong), or the calculation in identify_hierarchy_dict needs to fix something to take into account the new reality.

@kuzeyron kuzeyron added the bug label Dec 6, 2024
@cmacdonald
Copy link
Contributor

i can confirm the tests failing and, I think, the original author of this test. I'll prepare a PR; getting the maintainers to merge it will be another matter!

@cmacdonald
Copy link
Contributor

Java 18:

{
'java.lang.Object': 3, 
'java.lang.Iterable': 3, 
'java.util.Collection': 2,
'java.util.AbstractCollection': 2, 
'java.util.List': 1, 
'java.util.AbstractList': 1, 
'java.util.RandomAccess': 1, 
'java.lang.Cloneable': 1, 
'java.io.Serializable': 1, 
'java.util.ArrayList': 0
}

Java 21:

{
'java.lang.Object': 3, 
'java.lang.Iterable': 4, 
'java.util.Collection': 3, 
'java.util.AbstractCollection': 2, 
'java.util.SequencedCollection': 2, 
'java.util.List': 1, 
'java.util.AbstractList': 1, 
'java.util.RandomAccess': 1, 
'java.lang.Cloneable': 1, 
'java.io.Serializable': 1, 
'java.util.ArrayList': 0
}

java.util.SequencedCollection was introduced as an interface in the Collection -> List hierarchy in Java 21. This meant that Iterable is the highest numbered interface.

As to whether Object not being the highest level is a problem, I note that autoclass() says https://github.com/kivy/pyjnius/blob/master/jnius/reflect.py#L232

    # we now walk the hierarchy, from top of the tree, identifying methods
    # hopefully we start at java.lang.Object

But classes that are already done are ignored. (Also the level numbers seem to be ignored in autoclass()?)

In this case, what could go wrong? I'm not sure anything unless there is a default method defined in the Iterable and also in Object (e.g. equals()?).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants