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

The resource method is called despite an IllegalArgumentException in ParamConverter::fromString #23266

Closed
mwirth opened this issue Oct 30, 2020 · 8 comments

Comments

@mwirth
Copy link

mwirth commented Oct 30, 2020

Environment Details

  • GlassFish Version (and build number):
  • JDK version: 1.8.0_252
  • OS: MacOS

Problem Description

As per contract a ParamConverter has to throw an IllegalArgumentException if the supplied string cannot be parsed or is null.

If an implementation of ParamConverter throws an IllegalArgumentException in ParamConverter::fromString the resource method is called anyway (with the default value) but the process chain should be stopped.

@mwirth mwirth changed the title ParamConverter The resource method is called despite an IllegalArgumentException in ParamConverter::fromString Oct 30, 2020
@smillidge
Copy link
Contributor

Can you provide more detail on the issue. Like version of Eclipse GlassFish, error messages, how to reproduce the issue etc.

@mwirth
Copy link
Author

mwirth commented Jun 11, 2021

GlassFish Version 2.33

How to reproduce:
Write a REST Service e.g.:

import java.util.regex.Pattern;
...
@RequestScoped
public class Service{
...
    @Path("pattern/{pattern}")
    @GET
    public String find(@PathParam("pattern") Pattern pattern){
        ...
        return ... 
    }

}

and use a ParamConverterProvider e.g. this one:

@Provider
public class PatternParamConverterProvider implements ParamConverterProvider {

    @Override
    public <T> ParamConverter<T> getConverter(final Class<T> rawType, final Type genericType, final Annotation[] annotations) {
        if (rawType.isAssignableFrom(Pattern.class))
            return (ParamConverter<T>) new ParamConverter<Pattern>() {

                @Override
                public final Pattern fromString(final String regex) {
                    throw new IllegalArgumentException(...);
                }

                @Override
                public final String toString(final Pattern pattern) {
                    return Optional.ofNullable(pattern).map(Pattern::pattern).orElse(null);
                }
            };
        return null;
    }

Do a REST-call to http://..../pattern/myPattern which calls the method find

--> fromString throws an exception, the resrouce method is called anyway.

@github-actions
Copy link

This issue has been marked as inactive and old and will be closed in 7 days if there is no further activity. If you want the issue to remain open please add a comment

@mkarg
Copy link
Member

mkarg commented Jun 18, 2024

@smillidge You asked for more details, they had been provided by @mwirth, but then nothing happened and the issue was auto-closed. So is this issue not reproducible or is it fixed?

@smillidge
Copy link
Contributor

@mkarg no idea it was 3 years ago and the version number wasn't an Eclipse GlassFish version.

@mkarg
Copy link
Member

mkarg commented Jun 25, 2024

So why not simply running the provided reproducer in latest GlassFish to see the bug in action?

@smillidge
Copy link
Contributor

time - if it still an issue for you reopen or create another issue?

dmatej added a commit to dmatej/glassfish that referenced this issue Jul 6, 2024
@dmatej
Copy link
Contributor

dmatej commented Jul 6, 2024

So why not simply running the provided reproducer in latest GlassFish to see the bug in action?

If it is so important for you, you could simply create a PR with the reproducer. I don't even know on which GlassFish version it did not work (2.33 does not exist), but on GlassFish 7.0.16-SNAPSHOT it works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants