Skip to content
Open
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 @@ -13,6 +13,7 @@
*
* Copyright 2010-2011 ApexIdentity Inc.
* Portions Copyright 2011-2016 ForgeRock AS.
* Portions Copyright 2026 3A Systems, LLC.
*/

package org.forgerock.openig.heap;
Expand Down Expand Up @@ -82,7 +83,7 @@ public static Heaplet getHeaplet(Class<?> c) {
try {
heaplet = c.asSubclass(Heaplet.class).newInstance();
} catch (Exception e) {
logger.warn("An error occurred while trying to instantiate %s as a Heaplet", c.getName(), e);
logger.warn("An error occurred while trying to instantiate {} as a Heaplet", c.getName(), e);
// Ignored
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2016 ForgeRock AS.
* Portions Copyright 2026 3A Systems, LLC.
*/

package org.forgerock.openig.util;
Expand Down Expand Up @@ -103,7 +104,7 @@ private JsonValue fetch(JsonValue location) {
URL url = location.as(url());
if (url == null) {
throw new JsonValueException(location,
format("$location value ({}) cannot be null (or evaluated to null)",
format("$location value (%s) cannot be null (or evaluated to null)",
location.getObject()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2014-2016 ForgeRock AS.
* Portions Copyright 2026 3A Systems, LLC.
*/

package org.forgerock.openig.heap;
Expand All @@ -31,9 +32,14 @@
import org.forgerock.openig.heap.domain.Editor;
import org.forgerock.openig.heap.domain.EditorHeapletFactory;
import org.forgerock.openig.heap.domain.Publisher;
import org.slf4j.LoggerFactory;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;

@SuppressWarnings("javadoc")
public class HeapletsTest {

Expand Down Expand Up @@ -103,4 +109,36 @@ public void shouldFailToFindAnyCompatibleHeaplet() throws Exception {
// inner class is private (not public)
assertThat(Heaplets.getHeaplet(Book4.class)).isNull();
}

@Test
public void shouldLogClassNameWhenHeapletCannotBeInstantiated() throws Exception {
Logger logger = (Logger) LoggerFactory.getLogger(Heaplets.class);
ListAppender<ILoggingEvent> appender = new ListAppender<>();
appender.start();
logger.addAppender(appender);
try {
assertThat(Heaplets.getHeaplet(BrokenHeaplet.class)).isNull();
} finally {
logger.detachAppender(appender);
}

assertThat(appender.list).hasSize(1);
ILoggingEvent event = appender.list.get(0);
assertThat(event.getFormattedMessage())
.isEqualTo("An error occurred while trying to instantiate "
+ BrokenHeaplet.class.getName() + " as a Heaplet");
assertThat(event.getThrowableProxy()).isNotNull();
}

/** A heaplet whose constructor always fails. */
public static class BrokenHeaplet extends GenericHeaplet {
public BrokenHeaplet() {
throw new IllegalStateException("Cannot be instantiated");
}

@Override
public Object create() throws HeapException {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2016 ForgeRock AS.
* Portions Copyright 2026 3A Systems, LLC.
*/

package org.forgerock.openig.util;

import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.data.MapEntry.entry;
import static org.forgerock.json.JsonValue.array;
import static org.forgerock.json.JsonValue.field;
Expand Down Expand Up @@ -85,6 +87,13 @@ public void shouldThrowExceptionIfNotValidURL(JsonValue value) throws Exception
value.as(resolveLocation);
}

@Test
public void shouldReportTheValueWhenLocationIsNull() {
assertThatThrownBy(() -> json(object(field("$location", null))).as(resolveLocation))
.isInstanceOf(JsonValueException.class)
.hasMessageContaining("$location value (null) cannot be null (or evaluated to null)");
}

@Test
public void shouldEvaluateExpressions() throws IOException {
// Create the test file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public Promise<Response, NeverThrowsException> apply(final JsonValue policyDecis
}

// Should never happen
logger.error("Returned resource ('{}' does not match current request URI (''))", resource, original);
logger.error("Returned resource ('{}') does not match current request URI ('{}')", resource, original);
return newResponsePromise(newInternalServerError());
}
};
Expand Down
Loading