File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed
rxjava-core/src/main/java/rx/exceptions Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -116,7 +116,7 @@ public static class OnNextValue extends RuntimeException {
116116 * the item that the Observable was trying to emit at the time of the exception
117117 */
118118 public OnNextValue (Object value ) {
119- super ("OnError while emitting onNext." );
119+ super ("OnError while emitting onNext value: " + renderValue ( value ) );
120120 this .value = value ;
121121 }
122122
@@ -129,5 +129,25 @@ public Object getValue() {
129129 return value ;
130130 }
131131
132+ /**
133+ * Render the object if it is a basic type. This avoids the library making potentially expensive
134+ * or calls to toString() which may throw exceptions. See PR #1401 for details.
135+ *
136+ * @param value
137+ * the item that the Observable was trying to emit at the time of the exception
138+ * @return a string version of the object if primitive, otherwise the classname of the object
139+ */
140+ private static String renderValue (Object value ){
141+ if (value == null ){
142+ return "null" ;
143+ }
144+ if (value .getClass ().isPrimitive ()){
145+ return value .toString ();
146+ }
147+ if (value instanceof String ){
148+ return (String )value ;
149+ }
150+ return value .getClass ().getSimpleName () + ".class" ;
151+ }
132152 }
133153}
You can’t perform that action at this time.
0 commit comments