File tree Expand file tree Collapse file tree 2 files changed +14
-10
lines changed
src/main/java/org/scijava/object Expand file tree Collapse file tree 2 files changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -110,14 +110,16 @@ public void removeObject(final Object obj) {
110
110
111
111
@ Override
112
112
public String getName (Object obj ) {
113
- String name = objectIndex .getName (obj );
114
- if (name != null ) {
115
- return name ;
116
- }
113
+ if (obj == null ) throw new NullPointerException ();
114
+ final String name = objectIndex .getName (obj );
115
+ if (name != null ) return name ;
117
116
if (obj instanceof Named ) {
118
- return ((Named ) obj ).getName ();
117
+ final String n = ((Named ) obj ).getName ();
118
+ if (n != null ) return n ;
119
119
}
120
- return obj .toString ();
120
+ final String s = obj .toString ();
121
+ if (s != null ) return s ;
122
+ return obj .getClass ().getName () + "@" + Integer .toHexString (obj .hashCode ());
121
123
}
122
124
123
125
// -- Service methods --
Original file line number Diff line number Diff line change @@ -57,11 +57,13 @@ default EventService eventService() {
57
57
58
58
/**
59
59
* Gets the name belonging to a given object.
60
- *
60
+ * <p>
61
61
* If no explicit name was provided at registration time, the name will be
62
- * derived from {@link Named#getName()} if the object implements {@link Named},
63
- * or from the {@link Object#toString()} otherwise
64
- **/
62
+ * derived from {@link Named#getName()} if the object implements
63
+ * {@link Named}, or from the {@link Object#toString()} otherwise. It is
64
+ * guaranteed that this method will not return {@code null}.
65
+ * </p>
66
+ */
65
67
String getName (Object obj );
66
68
67
69
/** Registers an object with the object service. */
You can’t perform that action at this time.
0 commit comments