Failed product PropertySet

Source: Internet
Author: User

Good idea, failed product-PropertySet

PropertySet is indeed a good thing. As for how good it is, I will not say it. Let's see it on your own.

However, PropertySet does make me very angry. I did not succeed in the experiment for one night, but the problem lies in its source code! Let me talk about it slowly.

How simple is the simplest example? Look at the configuration file and you will know:

<Propertysets>

<Propertyset name = "myBean" class = "testLab. MyBean">

<Arg name = "myInt" value = "57"/>

<Arg name = "myString" value = "na57"/>

</Propertyset>

</Propertysets>

 

This example is just to read the values I need from the configuration file. My test code is as follows:

PropertySet ps = PropertySetManager. getInstance ("myBean", null );

System. out. print (ps. getString ("myString "));

Assert. assertEquals ("na57", ps. getString ("myString "));

 

The result failed. Where is the failure? I checked the PropertySet Code while keeping my code safe. The implementation of the PropertySet interface is the MemoryPropertySet class, so I first found the code for reading data in this class:

Public String getString (String key ){

Try {

Return (String) get (STRING, key );

} Catch (NullPointerException e ){

Return null;

}

}

The following is the get method:

Protected synchronized Object get (int type, String key) throws InvalidPropertyTypeException {

If (exists (key )){

ValueEntry v = (ValueEntry) getMap (). get (key );

 

If (v. type! = Type ){

Throw new InvalidPropertyTypeException ();

}

 

Return v. value;

} Else {

Return null;

}

}

Then the getMap () method is used:

Protected HashMap getMap (){

Return map;

}

There is no problem here. Next we need to see where map is assigned. map is a private field of the MemoryPropertySet class. Naturally, it will not be assigned a value in the base class of MemoryPropertySet. However, in the MemoryPropertySet class, the map assignment operation has only one place:

Public void init (Map config, Map args ){

Map = new HashMap ();

}

 

I will not talk about it any more. There is nothing in map at all, and I am dizzy ~~~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.