WALA
WALA copied to clipboard
ArrayClass,getSuperClass() implementation doesn't comply with Java Language Spec
Hi guys,
just starting with WALA and I noticed one dodgy thing in com.ibm.wala.classLoader.ArrayClass#getSuperclass implementation. According to WALA 1.5.2 code, in case that we have array class for array Sub[], and Sub class is a subclass of Base class, it returns class for Base[] array. Which seems wrong, as there's no array class hierarchy in Java - all arrays (no exceptions) inherit directly from Object class.
Refer to e.g. https://www.geeksforgeeks.org/array-primitive-type-object-java/ for details (I also tried a simple test to make sure the article is right).
So, it the com.ibm.wala.classLoader.ArrayClass#getSuperclass behaviour intentional (in that case, please add some comments why) or is it really a bug?
Thanks, Richard
My guess is that this code was implemented with Java’s covariant array subtyping relation in mind: https://docs.oracle.com/javase/specs/jls/se12/html/jls-4.html#jls-4.10.3. But subtyping is not the same thing as subclassing, as the language specification explicitly points out in the case of arrays: https://docs.oracle.com/javase/specs/jls/se12/html/jls-10.html#jls-10.1. In light of the latter, I agree that getSuperClass is behaving incorrectly here, or at the very least is misleadingly named.
I agree the behavior is inconsistent with Java subtyping rules. It does seem based on the yuck
here that this was deliberate:
https://github.com/wala/WALA/blob/fac89b228f101eb5367cdda29b4d432af52c999d/com.ibm.wala.core/src/com/ibm/wala/classLoader/ArrayClass.java#L129-L134
I don't really know why it was done this way though. @juliandolby do you have any insight?
@Nogyara is this causing some other breakage in your use case?
Thanks for quick reply and references to Java Language Specification. @msridhar No, we don't have any immediate problems with the current implementation (we're at the early stages of development) but it's a thing I notices and didn't seem right so I decided to open an issue for it.