You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tamaya.apache.org by "Anatole Tresch (JIRA)" <ji...@apache.org> on 2017/02/26 22:48:46 UTC
[jira] [Resolved] (TAMAYA-235) The get method of the
MappedConfiguration class may throw a NullPointerException
[ https://issues.apache.org/jira/browse/TAMAYA-235?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Anatole Tresch resolved TAMAYA-235.
-----------------------------------
Resolution: Fixed
Fix Version/s: 0.3-incubating
> The get method of the MappedConfiguration class may throw a NullPointerException
> --------------------------------------------------------------------------------
>
> Key: TAMAYA-235
> URL: https://issues.apache.org/jira/browse/TAMAYA-235
> Project: Tamaya
> Issue Type: Bug
> Components: Extensions
> Affects Versions: 0.2-incubating
> Reporter: Francois MESSIAEN
> Assignee: Anatole Tresch
> Fix For: 0.3-incubating
>
>
> When the parameter "stripKeys" is set true in the section method of the ConfigurationFunctions class, the behavior of the get method MappedConfiguration is incoherent : the section name has to be prepend twice in order to get the value.
> The following code source is based on the "02-custom-property-source" example project.
> {code:java|title=Main.java}
> public static void main(String[] args) {
> // keep original section name
> // testSection(false);
> // strip section name
> testSection(true);
> }
>
> private static void testSection(boolean stripKeys){
> Configuration cfg = ConfigurationProvider.getConfiguration().with(ConfigurationFunctions.section("example.", stripKeys));
> System.out.println("*****************************************************");
> System.out.println("stripKeys: " + stripKeys);
> System.out.println("*****************************************************");
> dump(cfg.getProperties(), System.out);
> System.out.println();
> System.out.println("Example Metadata:");
> System.out.println("\texample.type : " + cfg.get("example.type"));
> System.out.println("\texample.example.type : " + cfg.get("example.example.type"));
> System.out.println("\ttype : " + cfg.get("type"));
> dump(cfg.getProperties(), System.out);
> }
> private static void dump(Map<String, String> properties, PrintStream stream) {
> stream.println("FULL DUMP:");
> for (Map.Entry<String, String> en : new TreeMap<>(properties).entrySet()) {
> stream.println(format("\t%s = %s", en.getKey(), en.getValue()));
> }
> }
> {code}
> This is the result of the execution :
> {noformat}
> *****************************************************
> stripKeys: true
> *****************************************************
> FULL DUMP:
> author = anatole@apache.org
> description = A minimal example using an self written property source.
> name = simple-propertysource
> type = standalone
> version = 1
> Example Metadata:
> example.type : null
> example.example.type : standalone
> Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -4
> at java.lang.String.substring(String.java:1931)
> at org.apache.tamaya.functions.ConfigurationFunctions$5$2.mapKey(ConfigurationFunctions.java:235)
> at org.apache.tamaya.functions.MappedConfiguration.get(MappedConfiguration.java:79)
> at org.apache.tamaya.functions.MappedConfiguration.get(MappedConfiguration.java:74)
> at org.apache.tamaya.functions.MappedConfiguration.get(MappedConfiguration.java:51)
> at org.apache.tamaya.examples.custompropertysource.Main.testSection(Main.java:84)
> at org.apache.tamaya.examples.custompropertysource.Main.main(Main.java:71)
> {noformat}
> In the dump of the MappedConfiguration, the "standalone" value is associated to the "type" key".
> When calling the get method of the MappedConfiguration, the "standalone" value is got by prepending twice the "example." section name in the "type" key.
> Without adding the section name, a NullPointerException is thrown.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)