j2objc exception prevents unit tests running

205 views Asked by At

I'm working on an app that uses a cocoapod, which has been built using j2objc. But when I try to run unit tests in Xcode I see the following error:

Terminating app due to uncaught exception 'JavaLangArrayStoreException', reason: 'source of type IOSByteArray is not an array'

I understand that arrays in Java don't map perfectly onto Objective C arrays. But this exception doesn't prevent the app from running, so is there a way to ignore this for unit tests and UI tests?

The code that's failing is inside a cocoapod, so I'm not sure I'll be able to do any manual conversions. Here's the line that's failing:

return IOSObjectArray_Get(nil_chk([rawType getGenericInterfaces]), i);
2

There are 2 answers

1
Vyacheslav On

I do not know your code but you must understand that array of Objective-C is not -the same as IOSByteArray!

You have to convert IOSByteArray into usual objc array before using of it.

use either this

- (void)getBytes:(jbyte *)buffer
          offset:(jint)offset
          length:(jint)length;

or this

- (NSData *)toNSData;

method to work.

0
tball On

That doesn't look like the line that's failing. That error message is from System.arraycopy, which failed saying that IOSByteArray isn't a subclass of IOSArray, which it is. IOSObjectArray only throws an ArrayStoreException here, with a different error message.

Do you have the source to the unit test, and if so, can you post it or its project (if it's open-source)? If you file a j2objc issue with the failing test, you'll be notified as soon as it's fixed.

If this is a JUnit test, you can surround the failing line with a try/catch block just like in Java. Or comment it out. ;-)