diff --git a/ext/objspace/objspace_dump.c b/ext/objspace/objspace_dump.c index 7a5f44aaad..544d11e254 100644 --- a/ext/objspace/objspace_dump.c +++ b/ext/objspace/objspace_dump.c @@ -471,10 +471,15 @@ dump_object(VALUE obj, struct dump_config *dc) dump_append(dc, "]"); if (ainfo) { - dump_append(dc, ", \"file\":\""); - dump_append(dc, ainfo->path); - dump_append(dc, "\", \"line\":"); - dump_append_lu(dc, ainfo->line); + if (ainfo->path) { + dump_append(dc, ", \"file\":\""); + dump_append(dc, ainfo->path); + dump_append(dc, "\""); + } + if (ainfo->line) { + dump_append(dc, ", \"line\":"); + dump_append_lu(dc, ainfo->line); + } if (RTEST(ainfo->mid)) { VALUE m = rb_sym2str(ainfo->mid); dump_append(dc, ", \"method\":");