Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value access calls toString() on failure, potentially leading to infi… #570

Merged
merged 1 commit into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}