https://kotlinlang.org logo
Title
g

Gopal S Akshintala

08/31/2021, 5:43 AM
Can someone help me understand what does this exception mean. I am trying to use
CollectionsKt
method directly in java and run this in a unit test. However this static import is causing this exception
import static kotlin.collections.CollectionsKt.chunked;
However, if I use
CollectionsKt.chunked(…)
without the static import, I don’t get this exception:
java.lang.IllegalAccessError: failed to access class kotlin.collections.CollectionsKt___CollectionsKt from class billing.batch.invoice.services.tax.TaxIntegrator (kotlin.collections.CollectionsKt___CollectionsKt and billing.batch.invoice.services.tax.TaxIntegrator are in unnamed module of loader org.powermock2.core.classloader.javassist.JavassistMockClassLoader @5443d039)
j

javaru

08/31/2021, 2:54 PM
That’s more likely being caused by PowerMock, which messes with the byte code. In this PowerMock issue, there is some discussion of using the
@PowerMockIgnore
annotation to resolve the
IllegalAccessError
problem in some cases. (As a side note, we were constantly running into issues with PowerMock in our project that we recently removed all use of it and are sticking with Mockito and MockK.)
g

Gopal S Akshintala

08/31/2021, 2:56 PM
Thanks Mark, but I get this exception when not using powermock as well... Do you have any idea what does that exception mean?
j

javaru

08/31/2021, 3:22 PM
Is the error happening at runtime, or compile time? The error basically means that something is trying to access or modify a field, or call a method, that it does not have access to. That is usually thrown at compile time. It can also be thrown at Runtime if the definition of a class has incompatibly changed. This can happen if you the version loaded at run time is different than that was used at compile time. (It may also happen at compile time if think you are using in the source code is different than what is being complied against. For example if the IDE and the build system are configured differently.) So I would check your compile time and runtime classpaths to make sure they are using the same version of the Kotlin JARs (and there are no cross version JARs such as v1.5.21 of one Kotlin JAR and v1.4.10 of another as an example). Also make sure the same version of Java is being used at both times.
So as I look at Kotlin v1.5.21 and v1.5.30 I do not see a
chunked
function in
kotlin.collections.Collections
. Perhaps it was in an old version, or was experimental? That would definitely cause the error.
g

Gopal S Akshintala

08/31/2021, 3:40 PM
Thanks @javaru I will check that…
chunked
has been there for quite long: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/chunked.html
j

javaru

08/31/2021, 3:44 PM
Strange. The doc you linked to says it’s there for 1.5. But in my project I can’t get it via code complete, and don’t see it when I open the source code.
g

Gopal S Akshintala

08/31/2021, 3:46 PM
if you are trying in java class,
import static kotlin.collections.CollectionsKt.chunked;
j

javaru

08/31/2021, 3:55 PM
Sorry, I must of had a typo somewhere when I tried before, as I’m seeing it now. I guess that’s what I get for trying to answer a Slack question while on a conference call.
And I was looking in the
Collections
source file rather than
_Collections