You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Steve Huston <sh...@riverace.com> on 2017/11/07 15:28:52 UTC

PropertyInject defaultValue doesn't work with zero-length string

I am using Camel 2.19.1 and have a question on @PropertyInject with a default value. I have the following:

public class MyStuff {
    @PropertyInject(value="testVal", defaultValue="")
    private String testVal;
...
}

When this class is instantiated and injected, if there is no 'testVal" in properties, I get an exception (below) that the testVal key is not found.

But if I change the defaultValue to anything non-empty, it works fine - the default value is used without a property of the given name.

Is this the way you would expect it to work?

Thanks,
-Steve

...
Caused by: org.apache.camel.RuntimeCamelException: java.lang.IllegalArgumentException: Property with key [testVal] not found in properties from text: {{testVal}}
	at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1774)
	at org.apache.camel.impl.CamelPostProcessorHelper.getInjectionPropertyValue(CamelPostProcessorHelper.java:282)
	at org.apache.camel.impl.DefaultCamelBeanPostProcessor.injectFieldProperty(DefaultCamelBeanPostProcessor.java:211)
	at org.apache.camel.impl.DefaultCamelBeanPostProcessor$1.doWith(DefaultCamelBeanPostProcessor.java:171)
	at org.apache.camel.util.ReflectionHelper.doWithFields(ReflectionHelper.java:74)
	at org.apache.camel.impl.DefaultCamelBeanPostProcessor.injectFields(DefaultCamelBeanPostProcessor.java:167)
	at org.apache.camel.impl.DefaultCamelBeanPostProcessor.postProcessBeforeInitialization(DefaultCamelBeanPostProcessor.java:82)
	at org.apache.camel.impl.DefaultInjector.newInstance(DefaultInjector.java:48)
	... 61 more
Caused by: java.lang.IllegalArgumentException: Property with key [ris.testOpk] not found in properties from text: {{ris.testOpk}}
	at org.apache.camel.component.properties.DefaultPropertiesParser$ParsingContext.getPropertyValue(DefaultPropertiesParser.java:271)
	at org.apache.camel.component.properties.DefaultPropertiesParser$ParsingContext.readProperty(DefaultPropertiesParser.java:157)
	at org.apache.camel.component.properties.DefaultPropertiesParser$ParsingContext.doParse(DefaultPropertiesParser.java:116)
	at org.apache.camel.component.properties.DefaultPropertiesParser$ParsingContext.parse(DefaultPropertiesParser.java:100)
	at org.apache.camel.component.properties.DefaultPropertiesParser.parseUri(DefaultPropertiesParser.java:63)
	at org.apache.camel.component.properties.PropertiesComponent.parseUri(PropertiesComponent.java:230)
	at org.apache.camel.component.properties.PropertiesComponent.parseUri(PropertiesComponent.java:173)
	at org.apache.camel.impl.DefaultCamelContext.resolvePropertyPlaceholders(DefaultCamelContext.java:2411)
	at org.apache.camel.impl.CamelPostProcessorHelper.getInjectionPropertyValue(CamelPostProcessorHelper.java:268)
	... 67 more


Re: PropertyInject defaultValue doesn't work with zero-length string

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

No as the annotation requires a value and thus "" is like not in use.
We would need to add a new attribute required boolean true|false so
you can set it to required = false.

You are welcome to log a JIRA and work on a github PR if you fancy

On Tue, Nov 7, 2017 at 4:28 PM, Steve Huston <sh...@riverace.com> wrote:
> I am using Camel 2.19.1 and have a question on @PropertyInject with a default value. I have the following:
>
> public class MyStuff {
>     @PropertyInject(value="testVal", defaultValue="")
>     private String testVal;
> ...
> }
>
> When this class is instantiated and injected, if there is no 'testVal" in properties, I get an exception (below) that the testVal key is not found.
>
> But if I change the defaultValue to anything non-empty, it works fine - the default value is used without a property of the given name.
>
> Is this the way you would expect it to work?
>
> Thanks,
> -Steve
>
> ...
> Caused by: org.apache.camel.RuntimeCamelException: java.lang.IllegalArgumentException: Property with key [testVal] not found in properties from text: {{testVal}}
>         at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1774)
>         at org.apache.camel.impl.CamelPostProcessorHelper.getInjectionPropertyValue(CamelPostProcessorHelper.java:282)
>         at org.apache.camel.impl.DefaultCamelBeanPostProcessor.injectFieldProperty(DefaultCamelBeanPostProcessor.java:211)
>         at org.apache.camel.impl.DefaultCamelBeanPostProcessor$1.doWith(DefaultCamelBeanPostProcessor.java:171)
>         at org.apache.camel.util.ReflectionHelper.doWithFields(ReflectionHelper.java:74)
>         at org.apache.camel.impl.DefaultCamelBeanPostProcessor.injectFields(DefaultCamelBeanPostProcessor.java:167)
>         at org.apache.camel.impl.DefaultCamelBeanPostProcessor.postProcessBeforeInitialization(DefaultCamelBeanPostProcessor.java:82)
>         at org.apache.camel.impl.DefaultInjector.newInstance(DefaultInjector.java:48)
>         ... 61 more
> Caused by: java.lang.IllegalArgumentException: Property with key [ris.testOpk] not found in properties from text: {{ris.testOpk}}
>         at org.apache.camel.component.properties.DefaultPropertiesParser$ParsingContext.getPropertyValue(DefaultPropertiesParser.java:271)
>         at org.apache.camel.component.properties.DefaultPropertiesParser$ParsingContext.readProperty(DefaultPropertiesParser.java:157)
>         at org.apache.camel.component.properties.DefaultPropertiesParser$ParsingContext.doParse(DefaultPropertiesParser.java:116)
>         at org.apache.camel.component.properties.DefaultPropertiesParser$ParsingContext.parse(DefaultPropertiesParser.java:100)
>         at org.apache.camel.component.properties.DefaultPropertiesParser.parseUri(DefaultPropertiesParser.java:63)
>         at org.apache.camel.component.properties.PropertiesComponent.parseUri(PropertiesComponent.java:230)
>         at org.apache.camel.component.properties.PropertiesComponent.parseUri(PropertiesComponent.java:173)
>         at org.apache.camel.impl.DefaultCamelContext.resolvePropertyPlaceholders(DefaultCamelContext.java:2411)
>         at org.apache.camel.impl.CamelPostProcessorHelper.getInjectionPropertyValue(CamelPostProcessorHelper.java:268)
>         ... 67 more
>



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2