Skip to content

Commit

Permalink
Value access calls toString() on failure, potentially leading to infi…
Browse files Browse the repository at this point in the history
…nite recursion #456 (#570)

Signed-off-by: Jorge Bescos Gascon <jorge.bescos.gascon@oracle.com>
  • Loading branch information
jbescos committed Aug 26, 2022
1 parent b65fb10 commit 5fb9f86
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void serialize(Object value, JsonGenerator generator, SerializationContex
try {
object = valueGetter.invoke(value);
} catch (Throwable e) {
throw new JsonbException("Error getting value on: " + value, e);
throw new JsonbException("Error getting value on: " + value.getClass().getName(), e);
}
delegate.serialize(object, generator, context);
}
Expand Down
45 changes: 45 additions & 0 deletions src/test/java/org/eclipse/yasson/Issue456Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

package org.eclipse.yasson;

import static org.junit.jupiter.api.Assertions.fail;

import org.junit.jupiter.api.Test;

import jakarta.json.bind.JsonbBuilder;
import jakarta.json.bind.JsonbException;

public class Issue456Test {

@Test
public void dontInvokeToString() {
try {
JsonbBuilder.create().toJson(new Example());
fail("JsonbException is expected");
} catch (JsonbException e) {
// Expected
}
}

public static class Example {

public String getProperty() {
throw new RuntimeException("some error");
}

@Override
public String toString() {
return JsonbBuilder.create().toJson(this);
}
}
}

0 comments on commit 5fb9f86

Please sign in to comment.