Startup fails if @Provider constructor has @ConfigProperty

236 views
Skip to first unread message

David Hoffer

unread,
Feb 3, 2021, 10:55:04 AM2/3/21
to Quarkus Development mailing list
I have a custom ContainerResponseFilter that Is marked as @Provider but gets config values from @ConfigProperty when created.  At startup I get NPE in ConstructorInjectorImpl line 55.  Why?

I have several other places where @ConfigProperty works fine in constructor. 

How to pass config values to ContainerResponseFilter?

-Dave

Georgios Andrianakis

unread,
Feb 3, 2021, 11:00:30 AM2/3/21
to David Hoffer, Quarkus Development mailing list
Unfortunately this is a problem we have seen before in RESTEasy Classic (it works as expected in RESTEasy Reactive).

I would suggest working around the problem using

ConfigProvider.getConfig().getValue(...)

--
You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quarkus-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/quarkus-dev/26a0fbd3-d6e0-407d-90b7-634cbf25d47en%40googlegroups.com.

Guillaume Smet

unread,
Feb 3, 2021, 11:00:49 AM2/3/21
to David Hoffer, Quarkus Development mailing list
Could you create a GitHub issue with a reproducer attached?

Thanks!

--

David Hoffer

unread,
Feb 3, 2021, 3:29:07 PM2/3/21
to Quarkus Development mailing list
I did use ConfigProvider.getConfig() as a workaround as was suggested however now that class can't be unit tested.

Also just some feedback on the  ConfigProvider.getConfig().getValue (String propertyName, Class<T> propertyType) operation.

It's not very friendly to use as my response type is List<String>.  So I had to change to this:

ConfigProvider.getConfig().getValue("app.response-headers", String[].class);

But that array can be empty and if that happens it throws NoSuchElementException...but it does exist...just empty.

So I have to do this:

String[] responseHeaders = new String[0];
try {
responseHeaders = ConfigProvider.getConfig().getValue( "app.response-headers"  , String[].class);
} catch (Exception ignored) {
}

Lot of code just to read one property.  Is getOptionalValue() to help solve this?  Does it catch the exception?  Even if actually does not exist?  I can't think of a good reason to ever throw...just want whatever exists if any.  Having a default value is useful but I don't see that option.

Thanks,
-Dave

George Gastaldi

unread,
Feb 3, 2021, 3:43:11 PM2/3/21
to David Hoffer, Quarkus Development mailing list
Use 

@Inject @ConfigProperty(name="yourprop")
Instance<List<String>> instance;

And call instance.get() inside your filter() method

Reply all
Reply to author
Forward
0 new messages