vikasfuter / google-gson

google-gson
0 stars 0 forks source link

StackOverFlow while converting a null object to json #622

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. create a null object activity
2. use gson.toJson(activity)
3. then cause stack overflow

What is the expected output? What do you see instead?

public String toJson(Object src) {
    if (src == null) {
      return toJson(JsonNull.INSTANCE);
    }
    return toJson(src, src.getClass());
  }

when you input a null object , it will create a null instance, then again and 
again

What version of the product are you using? On what operating system?

compile 'com.google.code.gson:gson:2.2.4'
on Anroid

Please provide any additional information below.

0
java.lang.StackOverflowError 1
... at 267 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:60) 268 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 269 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 270 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 271 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 272 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 273 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 274 at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:892) 275 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 276 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:96) 277 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:60) 278 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 279 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 280 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 281 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 282 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 283 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 284 at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:892) 285 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 286 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:96) 287 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:60) 288 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 289 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 290 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 291 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 292 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 293 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 294 at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:892) 295 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 296 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:96) 297 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:60) 298 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 299 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 300 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 301 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 302 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 303 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 304 at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:892) 305 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 306 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:96) 307 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:60) 308 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 309 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 310 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 311 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 312 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 313 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 314 at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:892) 315 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 316 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:96) 317 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:60) 318 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 319 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 320 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 321 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 322 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 323 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 324 at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:892) 325 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 326 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:96) 327 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:60) 328 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 329 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 330 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 331 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 332 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 333 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 334 at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:892) 335 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 336 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:96) 337 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:60) 338 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 339 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 340 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 341 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 342 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 343 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 344 at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:892) 345 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 346 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:96) 347 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:60) 348 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 349 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 350 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 351 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 352 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 353 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 354 at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:892) 355 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 356 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:96) 357 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:60) 358 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 359 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 360 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 361 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 362 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 363 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 364 at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:892) 365 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 366 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:96) 367 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:60) 368 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 369 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 370 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 371 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 372 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 373 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 374 at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:892) 375 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 376 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:96) 377 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:60) 378 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 379 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 380 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 381 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 382 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 383 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 384 at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:892) 385 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 386 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:96) 387 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:60) 388 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 389 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 390 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 391 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 392 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 393 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 394 at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:892) 395 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 396 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:96) 397 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:60) 398 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 399 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 400 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 401 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 402 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 403 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 404 at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:892) 405 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 406 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:96) 407 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:60) 408 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 409 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 410 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 411 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 412 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 413 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 414 at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:892) 415 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 416 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:96) 417 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:60) 418 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 419 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 420 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 421 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 422 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 423 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 424 at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:892) 425 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 426 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:96) 427 at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(Collect ionTypeAdapterFactory.java:60) 428 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 429 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 430 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 431 at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRun timeTypeWrapper.java:68) 432 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTyp eAdapterFactory.java:89) 433 at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(Reflect iveTypeAdapterFactory.java:195) 434 at com.google.gson.Gson.toJson(Gson.java:593) 435 at com.google.gson.Gson.toJson(Gson.java:572) 436 at com.google.gson.Gson.toJson(Gson.java:527) 437 at com.google.gson.Gson.toJson(Gson.java:507)

Original issue reported on code.google.com by lujiajin...@gmail.com on 26 Jan 2015 at 3:30