Closed ex3ndr closed 8 years ago
Do you have a test that shows this issue? Also, what is your default locale? I ask because this test works on my system. If it's related to locales, it may not on your system.
import java.security.*;
public final class GenerateId {
public static void main (String... arguments) {
try {
SecureRandom prng = SecureRandom.getInstance("SHA1PRNG");
String randomNum = new Integer(prng.nextInt()).toString();
MessageDigest sha = MessageDigest.getInstance("SHA-1");
byte[] result = sha.digest(randomNum.getBytes());
System.out.println("Random number: " + randomNum);
System.out.println("Message digest: " + byteArrayToHex(result));
} catch (NoSuchAlgorithmException ex) {
System.err.println(ex);
}
}
static String byteArrayToHex(byte[] a) {
StringBuilder sb = new StringBuilder(a.length * 2);
for(byte b : a) {
sb.append(String.format("%02x", b & 0xff));
}
return sb.toString();
}
}
Output:
$ j2objc GenerateId.java
translating GenerateId.java
Translated 1 file: 0 errors, 0 warnings
Translated 3 methods as functions
$ j2objcc GenerateId.m
$ ./a.out GenerateId
Random number: 8351987
Message digest: c56dd91563d8b0f2a84d48e3e38c8234a3dd5318
What system are you running this on? Mac command-line, simulator, ??? device, ...?
I am compiling on Mac, running on simulator or mac. I am creating SecureRandom with default constructor. Locales are different.
I try to use org.json library and produces something same - EXC_BAD_ACCESS. I used built-in library and manually copied to sources, but still same error.
I don't know why, but it crashes in lines in JSONTokenizer
in nextValue()
method:
StringBuilder sb = new StringBuilder();
while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) { // << HERE
sb.append(c);
c = this.next();
}
this.back();
Founded problem with JSON and created separated issue: #542 But it seems to be similar problem.
What JSON library are you having trouble with? I'd need the project link to proceed. Even better would be a test that shows the problem.
On Sun, May 24, 2015 at 7:29 PM Stepan Korshakov notifications@github.com wrote:
Founded problem with JSON and created separated issue: #542 https://github.com/google/j2objc/issues/542 But it seems to be similar problem.
— Reply to this email directly or view it on GitHub https://github.com/google/j2objc/issues/534#issuecomment-105095610.
I ask because the JSONTokenizer lines you included work for me.
I solved this issue by switching to different approach of building objc code. Instead of adding generated code manually to my project, i now build static library with gnu make and then link it to my project. I got same errors during process when i occasionaly disabled ARC, i guess this issue may have same case.
Unfortunately in latest (0.9.7) release there is some bug that prevents me of creating SecureRandom.
This is my stack trace: