As a best practice, do not catch the Exception class, instead catch specific subclasses. But, you do not need to catch any exceptions in this particular case? Can't you just verify whether the indexingConfiguration element is available or not?
KasunG On Wed, Sep 10, 2014 at 4:39 AM, Nipuni Perera <nip...@wso2.com> wrote: > Hi, > > I am working on issue[1]. I could find that the RegistryConfigLoader() > returns a null value. (line 73 in [2]). > > OMElement indexingConfig = configElement.getFirstChildWithName(new > QName("indexingConfiguration")); > > This value is used in several places. but NPE is thrown in line 88, > > lastAccessTimeLocation = indexingConfig.getFirstChildWithName(new > QName("lastAccessTimeLocation")).getText(); > > as the catch clause catches only > > catch (OMException e) { > ... // set default value > } > > while in other places (eg: line 78,79) it is > > catch (Exception e) { > ... // set default value > } > > This exception occurred due to a missing XML elements in registry.xml. > This missing element ( <indexingConfiguration> </indexingConfiguration> ) > will be used if the product is using registry search feature. But this NPE > should be handled for the products that does not use this feature. This can > be fixed adding similar catch clause (catching Exception e ) in the catch > clause(line 90,91) (current implementation use catch clauses to set default > values if an exception occurs. Adding an extra catch clause to the later > try block can be used to add similar behavior). Is there a better way to > handle this? > > [1] https://wso2.org/jira/browse/CARBON-14904 > [2] > https://githubc.com/Nipuni/carbon-registry/blob/master/components/registry/org.wso2.carbon.registry.indexing/src/main/java/org/wso2/carbon/registry/indexing/RegistryConfigLoader.java > <https://github.com/Nipuni/carbon-registry/blob/master/components/registry/org.wso2.carbon.registry.indexing/src/main/java/org/wso2/carbon/registry/indexing/RegistryConfigLoader.java> > > Thanks, > Nipuni > -- > Nipuni Perera > Software Engineer; WSO2 Inc.; http://wso2.com > Email: nip...@wso2.com > Git hub profile: https://github.com/nipuni > Mobile: +94 (71) 5626680 > <http://wso2.com> > > > _______________________________________________ > Dev mailing list > Dev@wso2.org > http://wso2.org/cgi-bin/mailman/listinfo/dev > > -- *Kasun Gajasinghe*Senior Software Engineer, WSO2 Inc. email: kasung AT spamfree wso2.com linked-in: http://lk.linkedin.com/in/gajasinghe blog: http://kasunbg.org
_______________________________________________ Dev mailing list Dev@wso2.org http://wso2.org/cgi-bin/mailman/listinfo/dev