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

sanitizePath method in JaxrsClientReactiveProcessor lacks null check #45272

Open
geekscloud opened this issue Dec 24, 2024 · 1 comment
Open
Labels
area/rest-client triage/needs-feedback We are waiting for feedback.

Comments

@geekscloud
Copy link

geekscloud commented Dec 24, 2024

Describe the bug

The sanitizePath method in JaxrsClientReactiveProcessor does not perform a null check on its input parameter path. This could result in a NullPointerException if the path argument is null. This issue may occur when external or user-defined configurations provide a null value.

Steps to Reproduce:

  1. Configure a REST Client or JAX-RS path with a null or uninitialized value.
  2. Observe that the application fails with a NullPointerException.

Example:

    private String sanitizePath(String path, boolean removesTrailingSlash) {
        if (!path.startsWith("/")) {
            path = "/" + path;
        }

        // For the client side, by default, we're only removing the trailing slash for the
        // `@Path` annotations at class level which is configurable.
        if (removesTrailingSlash && path.endsWith("/")) {
            path = path.substring(0, path.length() - 1);
        }
        return path;
    }

Proposed Fix:
Add a null check to the sanitizePath method to handle null or empty input values gracefully.

Suggested updated implementation:

    private String sanitizePath(String path, boolean removesTrailingSlash) {
        if (path != null) {
            if (!path.startsWith("/")) {
                path = "/" + path;
            }

            // For the client side, by default, we're only removing the trailing slash for the
            // `@Path` annotations at class level which is configurable.
            if (removesTrailingSlash && path.endsWith("/")) {
                path = path.substring(0, path.length() - 1);
            }
        }
        return path;
    }

Expected behavior

The method should handle null values gracefully and avoid throwing a NullPointerException.

Actual behavior

A NullPointerException is thrown when path is null.

How to Reproduce?

Steps to Reproduce:

  1. Configure a REST Client or JAX-RS path with a null or uninitialized value.
  2. Observe that the application fails with a NullPointerException.

Output of uname -a or ver

No response

Output of java -version

Java 11/17/21

Quarkus version or git rev

3.17.0.CR1

Build tool (ie. output of mvnw --version or gradlew --version)

Gradle/Maven

Additional information

The method is located in the following file:

Please consider adding this fix to ensure the method is more robust and does not fail unexpectedly when encountering null inputs.

@geekscloud geekscloud added the kind/bug Something isn't working label Dec 24, 2024
@geoand
Copy link
Contributor

geoand commented Dec 24, 2024

Thanks for reporting.

As far as I can tell, path is always non null. Do you have a sample that triggers the NPE?

@geoand geoand added kind/bug Something isn't working triage/needs-feedback We are waiting for feedback. area/rest-client and removed kind/bug Something isn't working triage/needs-triage labels Dec 24, 2024
@gsmet gsmet removed the kind/bug Something isn't working label Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/rest-client triage/needs-feedback We are waiting for feedback.
Projects
None yet
Development

No branches or pull requests

3 participants