Can someone help me understand what does this exce...
# getting-started
g
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
Copy code
import static kotlin.collections.CollectionsKt.chunked;
However, if I use
CollectionsKt.chunked(…)
without the static import, I don’t get this exception:
Copy code
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
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
Thanks Mark, but I get this exception when not using powermock as well... Do you have any idea what does that exception mean?
j
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
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
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
if you are trying in java class,
import static kotlin.collections.CollectionsKt.chunked;
j
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