1
1
/*
2
- * Copyright (c) 2009, 2015 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2009, 2022 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
23
23
24
24
/*
25
25
* @test
26
- * @bug 6797535 6889858 6891113 8013712 8011800 8014365
26
+ * @bug 6797535 6889858 6891113 8013712 8011800 8014365 8280168
27
27
* @summary Basic tests for methods in java.util.Objects
28
- * @author Joseph D. Darcy
29
28
*/
30
29
31
30
import java .util .*;
@@ -40,6 +39,7 @@ public static void main(String... args) {
40
39
errors += testHash ();
41
40
errors += testToString ();
42
41
errors += testToString2 ();
42
+ errors += testToIdentityString ();
43
43
errors += testCompare ();
44
44
errors += testRequireNonNull ();
45
45
errors += testIsNull ();
@@ -134,6 +134,37 @@ private static int testToString2() {
134
134
return errors ;
135
135
}
136
136
137
+ private static int testToIdentityString () {
138
+ int errors = 0 ;
139
+ // Test null behavior
140
+ try {
141
+ Objects .toIdentityString (null );
142
+ errors ++;
143
+ } catch (NullPointerException npe ) {
144
+ ; // Expected
145
+ }
146
+ // Behavior on typical objects
147
+ Object o = new Object (){};
148
+ errors += (Objects .toIdentityString (o ).equals (o .toString ()))? 0 : 1 ;
149
+ // Verify object's toString *not* called
150
+ Object badToString = new Object () {
151
+ @ Override
152
+ public String toString () {
153
+ throw new RuntimeException ();
154
+ }
155
+ };
156
+ Objects .toIdentityString (badToString );
157
+ // Verify object's hashCode *not* called
158
+ Object badHashCode = new Object () {
159
+ @ Override
160
+ public int hashCode () {
161
+ throw new RuntimeException ("0xDEADBEFF" );
162
+ }
163
+ };
164
+ Objects .toIdentityString (badHashCode );
165
+ return errors ;
166
+ }
167
+
137
168
private static int testCompare () {
138
169
int errors = 0 ;
139
170
String [] values = {"e. e. cummings" , "zzz" };
0 commit comments