jackrabbit-oak-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marcel Reutegger <mreut...@adobe.com>
Subject assert
Date Thu, 06 Sep 2012 12:36:30 GMT
hi,

I noticed a number of asserts in the code that tries to enforce (?)
constraints in the method contract. IMO this is problematic. assert
statements are only evaluated when enabled explicitly. usually
this only happens when tests run and a production system will
not run with asserts. this means we shouldn't use asserts to
enforce the method contract of a public method. one example
is RootImpl.getLocation(String):

    public TreeLocation getLocation(String path) {
        // TODO: must not use assertion to check contract! asserts must be enabled explicitly
        assert path.startsWith("/");
        return rootTree.getLocation().getChild(path.substring(1));
    }

the method will work correctly with assertions enabled, but fail
when assertions are disabled and the passed path is relative. you
wouldn't even notice it right away, because the method will just
cut the first character and move on.

I think we need to throw an exception in this case. IllegalArgumentException?

regards
 marcel

Mime
View raw message