Skip to content

Commit be60b93

Browse files
tomballkstanger
authored andcommitted
Automated g4 rollback.
*** Reason for rollback *** Issues mixing Java objects in native containers, like NSDictionary. *** Original change description *** Issue 423: fixed String.hashCode() to match JRE results. *** Change on 2014/11/18 by tball <[email protected]> ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=80229801
1 parent 1bef094 commit be60b93

File tree

14 files changed

+30
-99
lines changed

14 files changed

+30
-99
lines changed

jre_emul/Classes/IOSPrimitiveClass.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ - (BOOL)isEqual:(id)anObject {
130130
}
131131

132132
- (NSUInteger)hash {
133-
return [name_ hashCode];
133+
return [name_ hash];
134134
}
135135

136136
- (NSString *)binaryName {

jre_emul/Classes/JavaObject.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535
// Returns the IOSClass of the receiver.
3636
- (IOSClass *)getClass;
3737

38-
// Returns a hash code value for the object.
39-
- (jint)hashCode;
40-
4138
// Wakes up a waiting thread (if any).
4239
- (void)notify;
4340

@@ -46,8 +43,8 @@
4643

4744
// Waits until another thread wakes it, or times out.
4845
- (void)wait;
49-
- (void)waitWithLong:(jlong)timeout;
50-
- (void)waitWithLong:(jlong)timeout withInt:(int)nanos;
46+
- (void)waitWithLong:(long long)timeout;
47+
- (void)waitWithLong:(long long)timeout withInt:(int)nanos;
5148

5249
@end
5350

jre_emul/Classes/NSObject+JavaObject.m

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ - (IOSClass *)getClass {
5656
return [IOSClass classWithClass:[self class]];
5757
}
5858

59-
- (jint)hashCode {
60-
return (jint)[self hash];
61-
}
62-
6359
- (int)compareToWithId:(id)other {
6460
#if __has_feature(objc_arc)
6561
@throw [[JavaLangClassCastException alloc] init];
@@ -163,7 +159,6 @@ + (J2ObjcClassInfo *)__metadata {
163159
{ "isEqual:", "equals", "Z", 0x1, NULL },
164160
{ "clone", NULL, "LJavaLangObject", 0x4, "JavaLangCloneNotSupportedException" },
165161
{ "dealloc", "finalize", "V", 0x4, "JavaLangThrowable" },
166-
{ "hashCode", NULL, "I", 0x1, NULL },
167162
{ "notify", NULL, "V", 0x11, NULL },
168163
{ "notifyAll", NULL, "V", 0x11, NULL },
169164
{ "waitWithLong:", "wait", "V", 0x11, "JavaLangInterruptedException" },
@@ -173,7 +168,7 @@ + (J2ObjcClassInfo *)__metadata {
173168
{ "hash", "hashCode", "I", 0x1, NULL },
174169
};
175170
static J2ObjcClassInfo _JavaLangObject = {
176-
"Object", "java.lang", NULL, 0x1, 10, methods, 0, NULL, 0, NULL
171+
"Object", "java.lang", NULL, 0x1, 9, methods, 0, NULL, 0, NULL
177172
};
178173
return &_JavaLangObject;
179174
}

jre_emul/Classes/NSString+JavaString.m

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -930,16 +930,16 @@ - (BOOL)contentEqualsStringBuffer:(JavaLangStringBuffer *)sb {
930930
return [self isEqualToString:[sb description]];
931931
}
932932

933-
- (jint)hashCode {
933+
- (NSUInteger)hash {
934934
static const char *hashKey = "__JAVA_STRING_HASH_CODE_KEY__";
935935
id cachedHash = objc_getAssociatedObject(self, hashKey);
936936
if (cachedHash) {
937937
return [(JavaLangInteger *) cachedHash intValue];
938938
}
939-
jint len = (jint)[self length];
940-
jint hash = 0;
939+
int len = (int)[self length];
940+
int hash = 0;
941941
if (len > 0) {
942-
jchar *chars = malloc(len * sizeof(jchar));
942+
unichar *chars = malloc(len * sizeof(unichar));
943943
[self getCharacters:chars range:NSMakeRange(0, len)];
944944
for (int i = 0; i < len; i++) {
945945
hash = 31 * hash + (int)chars[i];
@@ -980,7 +980,6 @@ + (J2ObjcClassInfo *)__metadata {
980980
{ "getBytes", NULL, "[B", 0x1, NULL },
981981
{ "getBytesWithCharset:", NULL, "[B", 0x1, NULL },
982982
{ "getBytesWithCharsetName:", NULL, "[B", 0x1, "Ljava/io/UnsupportedEncodingException;" },
983-
{ "hashCode", NULL, "I", 0x1, NULL },
984983
{ "intern", NULL, "Ljava/lang/String;", 0x1, NULL },
985984
{ "isEmpty", NULL, "Z", 0x1, NULL },
986985
{ "matches:", NULL, "Z", 0x1, NULL },
@@ -1009,7 +1008,7 @@ + (J2ObjcClassInfo *)__metadata {
10091008
{ "serialPersistentFields_", NULL, 0x1a, "[Ljava/io/ObjectStreamField;", &NSString_serialPersistentFields_ },
10101009
{ "serialVersionUID_", NULL, 0x1a, "J", NULL, .constantValue.asLong = JavaLangString_serialVersionUID },
10111010
};
1012-
static J2ObjcClassInfo _JavaLangString = { "String", "java.lang", NULL, 0x1, 47, methods, 3, fields, 0, NULL};
1011+
static J2ObjcClassInfo _JavaLangString = { "String", "java.lang", NULL, 0x1, 46, methods, 3, fields, 0, NULL};
10131012
return &_JavaLangString;
10141013
}
10151014

jre_emul/Classes/java/lang/reflect/Field.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ - (BOOL)isEqual:(id)anObject {
350350
}
351351

352352
- (NSUInteger)hash {
353-
return [[declaringClass_ getName] hashCode] ^ [[self propertyName] hashCode];
353+
return [[declaringClass_ getName] hash] ^ [[self propertyName] hash];
354354
}
355355

356356
#if ! __has_feature(objc_arc)

jre_emul/Classes/java/text/IOSCollator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void setStrength(int value) {
8585

8686
@Override
8787
public native int hashCode() /*-[
88-
return (jint) [(NSLocale *) self->nsLocale_ hash];
88+
return [(NSLocale *) self->nsLocale_ hash];
8989
]-*/;
9090

9191
@Override

jre_emul/Tests/StringHashTest.java

Lines changed: 0 additions & 64 deletions
This file was deleted.

jre_emul/stub_classes/java/lang/String.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public int length() {
223223
public boolean matches(String s) {
224224
return false;
225225
}
226-
226+
227227
public int offsetByCodePoints(int index, int codePointOffset) {
228228
return 0;
229229
}
@@ -321,7 +321,10 @@ public int compare(String s1, String s2) {
321321
}
322322
}
323323

324-
public int hashCode() {
325-
return 0;
326-
}
324+
/* Unimplemented/mapped methods.
325+
String(byte[] bytes, int i, int j, java.nio.charset.Charset charset)
326+
String(byte[] bytes, java.nio.charset.Charset charset)
327+
byte[] getBytes(java.nio.charset.Charset charset)
328+
int offsetByCodePoints(int i, int j)
329+
*/
327330
}

jre_emul/tests.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ TEST_SOURCES = \
113113
ReentrantReadWriteLockTest.java \
114114
SerializationTest.java \
115115
ScheduledExecutorTest.java \
116-
StringHashTest.java \
117116
SynchronousQueueTest.java \
118117
ThreadPoolExecutorTest.java \
119118
TimeUnitTest.java \

translator/src/main/resources/com/google/devtools/j2objc/JRE.mappings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
# java.lang.Object
4242
java.lang.Object.equals(Ljava/lang/Object;)Z = NSObject isEqual:(id)anObject
4343
java.lang.Object.getClass()Ljava/lang/Class; = NSObject getClass
44+
java.lang.Object.hashCode()I = NSObject hash
4445
java.lang.Object.toString()Ljava/lang/String; = NSObject description
4546

4647
# java.lang.Class
@@ -190,6 +191,7 @@ java.lang.String.getChars(II[CI)V = \
190191
sourceEnd:(int)sourceEnd \
191192
destination:(IOSCharArray *)dest \
192193
destinationBegin:(int)dstBegin
194+
java.lang.String.hashCode()I = NSObject hash
193195
java.lang.String.indexOf(I)I = NSString indexOf:(int)ch
194196
java.lang.String.indexOf(II)I = NSString indexOf:(int)ch fromIndex:(int)index
195197
java.lang.String.indexOf(Ljava/lang/String;)I = NSString indexOfString:(int)s

translator/src/test/java/com/google/devtools/j2objc/gen/StatementGeneratorTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ public void testIntCastInStringConcatenation() throws IOException {
319319
+ " String b = \"foo\" + a.hashCode() + \"bar\" + a.length() + \"baz\"; } }",
320320
"Test", "Test.m");
321321
assertTranslation(translation,
322-
"JreStrcat(\"$I$I$\", @\"foo\", [a hashCode], @\"bar\", ((jint) [a length]),"
322+
"JreStrcat(\"$I$I$\", @\"foo\", ((jint) [a hash]), @\"bar\", ((jint) [a length]),"
323323
+ " @\"baz\")");
324324
}
325325

@@ -648,8 +648,8 @@ public void testCastInConstructorChain() throws IOException {
648648
List<Statement> stmts = translateStatements(source);
649649
assertEquals(1, stmts.size());
650650
String result = generateStatement(stmts.get(0));
651-
assertEquals("jint i = [((JavaLangThrowable *) "
652-
+ "[[[JavaLangThrowable alloc] init] autorelease]) hashCode];", result);
651+
assertEquals("jint i = ((jint) [((JavaLangThrowable *) "
652+
+ "[[[JavaLangThrowable alloc] init] autorelease]) hash]);", result);
653653
}
654654

655655
public void testInnerClassCreation() throws IOException {
@@ -1663,7 +1663,7 @@ public void testStringLengthCompare() throws IOException {
16631663
// Verify referenced return value is cast.
16641664
assertTranslation(translation, "return -2 < ((jint) [@\"1\" length]);");
16651665
// Verify unused return value isn't.
1666-
assertTranslation(translation, "[nil_chk(o) hashCode];");
1666+
assertTranslation(translation, "[nil_chk(o) hash];");
16671667
}
16681668

16691669
// Verify that casting from a floating point primitive to an integral primitive

translator/src/test/java/com/google/devtools/j2objc/translate/AutoboxerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public void testAutoboxCast() throws IOException {
339339
+ "public int hashCode() { return ((Double) doubleValue).hashCode(); } }";
340340
String translation = translateSourceFile(source, "Test", "Test.m");
341341

342-
assertTranslation(translation, "[JavaLangDouble_valueOfWithDouble_(doubleValue_) hashCode]");
342+
assertTranslation(translation, "[JavaLangDouble_valueOfWithDouble_(doubleValue_) hash]");
343343
}
344344

345345
public void testAutoboxArrayIndex() throws IOException {

translator/src/test/java/com/google/devtools/j2objc/translate/InnerClassExtractorTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void testSimpleInnerClass() throws IOException {
5151
assertTranslation(translation, "- (instancetype)initWithA:(A *)outer$;");
5252
translation = getTranslatedFile("A.m");
5353
assertTranslation(translation, "A *this$0_;");
54-
assertTranslation(translation, "[nil_chk(this$0_->o_) hashCode]");
54+
assertTranslation(translation, "[nil_chk(this$0_->o_) hash]");
5555
assertTranslation(translation, "A_B_set_this$0_(self, outer$);");
5656
}
5757

@@ -84,7 +84,7 @@ public void testInnerInnerClass() throws IOException {
8484
translation = getTranslatedFile("A.m");
8585
assertTranslation(translation, "A *this$0_;");
8686
assertTranslation(translation, "A_B *this$0_;");
87-
assertTranslation(translation, "[nil_chk(this$0_->this$0_->o_) hashCode]");
87+
assertTranslation(translation, "[nil_chk(this$0_->this$0_->o_) hash]");
8888
}
8989

9090
public void testWeakInnerInnerClass() throws IOException {
@@ -94,7 +94,7 @@ public void testWeakInnerInnerClass() throws IOException {
9494
String translation = translateSourceFile(source, "A", "A.m");
9595
assertTranslation(translation, "A *this$0_;");
9696
assertTranslation(translation, "__weak A_B *this$0_;");
97-
assertTranslation(translation, "[nil_chk(this$0_->this$0_->o_) hashCode]");
97+
assertTranslation(translation, "[nil_chk(this$0_->this$0_->o_) hash]");
9898
}
9999

100100
public void testInnerMethodAnonymousClass() throws IOException {
@@ -119,7 +119,7 @@ public void testInnerMethodAnonymousClass() throws IOException {
119119
assertTranslation(translation, "A_B *this$1_;");
120120
assertTranslation(translation, "jint val$j_;");
121121
assertTranslation(translation, "[super initWithA:outer$->this$0_]");
122-
assertTranslation(translation, "[nil_chk(this$1_->this$0_->o_) hashCode]");
122+
assertTranslation(translation, "[nil_chk(this$1_->this$0_->o_) hash]");
123123
}
124124

125125
/**

translator/src/test/java/com/google/devtools/j2objc/translate/JavaToIOSMethodTranslatorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void testStringHashCode() throws IOException {
9292
List<Statement> stmts = translateStatements(source);
9393
assertEquals(1, stmts.size());
9494
String result = generateStatement(stmts.get(0));
95-
assertEquals("jint test = [@\"foo\" hashCode];", result);
95+
assertEquals("jint test = ((jint) [@\"foo\" hash]);", result);
9696
}
9797

9898
public void testClassGetSuperclass() throws IOException {

0 commit comments

Comments
 (0)