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

Reduce noise from fuzzing, or various unexpected inputs #68

Merged
merged 1 commit into from
Jan 23, 2025
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 @@ -79,7 +79,8 @@ public String getMessage(String key, Object... values) throws MissingMessageExce
String message = getOptionalMessage(key, values);
if (message == null) {
ActionInvocation actionInvocation = invocationStore.getCurrent();
throw new MissingMessageException("Message could not be found for the URI [" + actionInvocation.actionURI + "] and key [" + key + "]");
String uri = actionInvocation != null ? actionInvocation.actionURI : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From looking at this and playing w/ it locally, it looks like the source of noise was from NPEs, which this 'solves', right?

Copy link
Member Author

@robotdan robotdan Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. It does solve the NPE.

I suppose we could also consider not logging this message at all if there is no action invocation. But my primary goal was to remove the NPE I saw in some customer logs.

throw new MissingMessageException("Message could not be found for the URI [" + uri + "] and key [" + key + "]");
}

return message;
Expand All @@ -96,7 +97,8 @@ public String getOptionalMessage(String key, Object... values) {

if (template == null) {
if (!"[ValidationException]".equals(key)) {
logger.debug("Message could not be found for the URI [{}] and key [{}]", actionInvocation.actionURI, key);
String uri = actionInvocation != null ? actionInvocation.actionURI : null;
logger.debug("Message could not be found for the URI [{}] and key [{}]", uri, key);
}

return null;
Expand Down Expand Up @@ -131,12 +133,13 @@ protected Queue<String> determineBundles(String bundle) {
* @return The message or null if it doesn't exist.
*/
protected String findMessage(ActionInvocation actionInvocation, String key) {
String message = findMessage(actionInvocation.actionURI, key);
String actionURI = actionInvocation != null ? actionInvocation.actionURI : "/";
String message = findMessage(actionURI, key);
if (message != null) {
return message;
}

ActionConfiguration config = actionInvocation.configuration;
ActionConfiguration config = actionInvocation != null ? actionInvocation.configuration : null;
if (config == null) {
return null;
}
Expand Down
7 changes: 5 additions & 2 deletions src/test/java/messages/package.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2001-2007, Inversoft Inc., All Rights Reserved
# Copyright (c) 2001-2025, Inversoft Inc., All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,4 +14,7 @@
# language governing permissions and limitations under the License.
#
key=Super Package Message
format_key=Super Package Message %s %s %s
format_key=Super Package Message %s %s %s

# Default messages
[blank]=Required
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001-2024, Inversoft Inc., All Rights Reserved
* Copyright (c) 2001-2025, Inversoft Inc., All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -142,6 +142,31 @@ public void missing() {
verify(store);
}

@Test
public void noActionInvocation() {
HTTPContext context = new HTTPContext(Path.of("src/test/java"));
ActionInvocationStore store = createStrictMock(ActionInvocationStore.class);
expect(store.getCurrent()).andReturn(null).times(3);
replay(store);

LocaleProvider localeProvider = createStrictMock(LocaleProvider.class);
expect(localeProvider.get()).andReturn(Locale.US).anyTimes();
replay(localeProvider);

ResourceBundleMessageProvider provider = new ResourceBundleMessageProvider(localeProvider, new WebControl(new ServletContainerResolver(context), configuration), store);
assertEquals(provider.getMessage("[blank]foo.bar"), "Required");

// Really missing
try {
provider.getMessage("[not_found]bar");
fail("Should have failed");
} catch (MissingMessageException e) {
// Expected
}

verify(store);
}

@Test
public void search() {
HTTPContext context = new HTTPContext(Path.of("src/test/java"));
Expand Down
5 changes: 4 additions & 1 deletion src/test/web/messages/package.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2001-2022, Inversoft Inc., All Rights Reserved
# Copyright (c) 2001-2025, Inversoft Inc., All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -23,3 +23,6 @@ format_key=Super Package Message %s %s %s
[UnsupportedContentType]=Unsupported [Content-Type] HTTP request header value of [%s].

[invalidJSON]=Unable to parse JSON. The property [%s] was invalid. The error was [%s]. The detailed exception was [%s].

# Default messages
[blank]=Required