jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Julian Reschke <julian.resc...@gmx.de>
Subject hasProperty vs getProperty
Date Tue, 12 Jun 2012 13:01:46 GMT
Hi there,

seen in SLING (JcrNodeResource.java):

// check stuff for nt:resource (or similar) nodes
if (node.hasProperty(JCR_MIMETYPE)) {

if (node.hasProperty(JCR_ENCODING)) {

if (node.hasProperty(JCR_LASTMODIFIED)) {
     // We don't check node type, so JCR_LASTMODIFIED might not be a long
     final Property prop = node.getProperty(JCR_LASTMODIFIED);
     try {
     } catch(ValueFormatException vfe) {
         LOGGER.debug("Property {} cannot be converted to a long, 
ignored ({})",
                 prop.getPath(), vfe);

if (node.hasProperty(JCR_DATA)) {
     final Property prop = node.getProperty(JCR_DATA);
     try {
     } catch (ValueFormatException vfe) {
             "Length of Property {} cannot be retrieved, ignored ({})",
             prop.getPath(), vfe);

So instead of just fetching the property, it checks for the presence 
first. This seems like a waste of time to me.

Is this just to avoid catching exceptions? (keep in mind that the 
exception might be thrown anyway...)

If the concern is that fetching properties that "most of the time" do 
not exist would be slow due to exceptions being constructed, then it 
might be worthwhile using


(which we then could optimized in jackrabbit-core).

Best regards, Julian

View raw message