You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tamaya.apache.org by "ASF subversion and git services (JIRA)" <ji...@apache.org> on 2017/02/26 23:05:47 UTC

[jira] [Commented] (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:comment-tabpanel&focusedCommentId=15884957#comment-15884957 ] 

ASF subversion and git services commented on TAMAYA-235:
--------------------------------------------------------

Commit d763fa0422fbe9f66f261c810dbbd3bdc1092654 in incubator-tamaya-extensions's branch refs/heads/master from [~anatole]
[ https://git-wip-us.apache.org/repos/asf?p=incubator-tamaya-extensions.git;h=d763fa0 ]

TAMAYA-235: Added tests for section method. Fixed invalid key mapping.


> 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)