-
Notifications
You must be signed in to change notification settings - Fork 29
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
Reference only property declared in *.properties file in property expression #206
Reference only property declared in *.properties file in property expression #206
Conversation
Here a demo with referenced property coming from Java which is forbidden: @fbricon what do you think about the error message : |
maybe "Cannot reference a property programmatically defined". @maxandersen wdyt |
Pinged @radcortez as he knows the "rules" better than I do. |
i.e. i'm surprised if programmatically defined properties can't be referred to ...thats news to me (but I kinda understand why ... but just wonder how you refer to http.port in a url without having to override the default ?) |
They can. They just need to be valid on runtime, when the expression is evaluated. The message |
@radcortez yeah so what you are saying ( which is what I thought too ) is that what is described in #205 does not hold true in all cases ? (not sure if spec is more restrictive and we allow it or @angelozerr interpreted the spec too strict ?) |
Yes, that is the exception. Consider: @ConfigProperty(name = "my.prop", defaultValue = "foo")
String foo;
@ConfigProperty(name = "my.prop", defaultValue = "bar")
String bar In this case, the same property may be injected in two different injection points with two different default values. If the default value is used, then how do you expand ${my.prop}? Is it |
@maxandersen according to the spec at https://download.eclipse.org/microprofile/microprofile-config-2.0/microprofile-config-spec-2.0.html#property-expressions it seems that we cannot reference property which comes from @ConfigProperty:
I tested this usecase in Quarkus application and when I try to reference a property coming from @ConfigProperty, the application cannot be started. It's the reason why I wanted to manage that,because I spend some time to understand why my Quarkus application could not be started. @radcortez you mean that it's not a correct validation? |
It's my error validation that I have implemented for the editor. |
I mean, I write a class with those following properties: @ConfigProperty(name="abcd")
private String abcd;
@ConfigProperty(name = "my.prop", defaultValue = "foo")
String foo;
@ConfigProperty(name = "my.prop", defaultValue = "bar")
String bar; And I try to configure
when I start the Quarkus application, I have this error:
and I cannot access to my web page. |
Correct, because there is no way right now to determine the value to use. Which value should |
Ok I understand, but when I write just: @ConfigProperty(name="abcd")
private String abcd;
@ConfigProperty(name = "my.prop", defaultValue = "bar")
String bar; I have the same error:
Is it a Quarkus bug? |
It's the same case. Even if you only have one injection point there and you could use the value from it, the case is disallowed because it is unreliable. For instance, a dependency of your application might use the same config. Or maybe someone else, later on, adds an injection point to the same config name in another part of the code. It doesn't make sense for the same configuration name to have two different values, but unfortunately, this is possible due to the way the My recommendation is to just set any default values in the properties files. Are you experiencing any issue that requires you to set the default in the annotation directly? |
Indeed if I write
So I think having validation for
@radcortez what do you think about that? |
No, I have just tested corner usecase to implement my validator. |
I think the message needs to state that you cannot use default properties to expand other values. For instance, nothing stops you to create your own |
You are speaking about Our tooling is able to scan According to my test, I cannot reference any MP or Quarkus properties coming from ConfigProperty, etc If you see my demo #206 (comment) if I assign value for a property which comes from Java (Quarkus annotation) inside properties file, it works. |
The spec says:
|
Yes, the same applies to Feel free to provide the message that suits best :) |
Many thanks @radcortez to take time to explain this behavior.
What do you think about :
|
Sounds good :) |
7cc29e1
to
e5c3d7c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine to merge when you're ready.
e5c3d7c
to
79281b1
Compare
expresion Fixes eclipse-lsp4mp#205 Signed-off-by: azerr <azerr@redhat.com>
All tests passed. I merge the PR. Thanks @rgrunber for your review! |
Reference only property declared in *.properties file in property expresion
Fixes #205
Signed-off-by: azerr azerr@redhat.com