1

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);
Adam Colvin
  • 751
  • 1
  • 6
  • 16

2 Answers2

0

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.

Vyacheslav
  • 26,359
  • 19
  • 112
  • 194
  • See the amended question. Converting the IOSByteArray would be the ideal solution, but I don't have direct access to it as it's inside a cocoapod. Also the exception doesn't cause the app to crash when I run it, so it would be good if there was a way to just ignore it. – Adam Colvin Dec 27 '16 at 21:58
0

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. ;-)

tball
  • 1,984
  • 11
  • 21