Hi,

following my previous mail, I discovered that IoFilterAdapter is not abstract may be because there is a cryptic method deep into DefaultIoFilterChainBuilder which tries to instanciate this class :

   public void setFilters(Map<String, ? extends IoFilter> filters) {
       if (filters == null) {
           throw new NullPointerException("filters");
       }
if (!isOrderedMap(filters)) {
           ...

   @SuppressWarnings("unchecked")
   private boolean isOrderedMap(Map map) {
       Class<?> mapType = map.getClass();
       ...
       Random rand = new Random();
       List<String> expectedNames = new ArrayList<String>();
IoFilter dummyFilter = new IoFilterAdapter(); <------------------------------this is here. for (int i = 0; i < 65536; i ++) { // WTF is this loop ???
           String filterName;
do {
               filterName = String.valueOf(rand.nextInt());
           } while (newMap.containsKey(filterName));
newMap.put(filterName, dummyFilter);
           expectedNames.add(filterName);

           Iterator<String> it = expectedNames.iterator();
           for (Object key: newMap.keySet()) {
               if (!it.next().equals(key)) {
                   if (logger.isDebugEnabled()) {
                       logger.debug(
"The specified map didn't pass the insertion " +
                               "order test after " + (i + 1) + " tries.");
                   }
                   return false;
               }
           }
       }


Now, for what it worths, I'm really puzzled about this part of the code : what is this suppose to do ??? There is _no_ explanation, this is typically such a portion of code which makes it almost impossible to maintain. I call it a one man show.

Plus I think it's totally useless. We can write defensive code, but at some point, we have to stop, and think. The setFilters( Map ) method is never called nowhere, and sounds like a YAGNI method to me. Why should we allow a user to create his own map, assume that the user can be malicious, and inject a cryptic method to check that the user didn't broke something in his own code ? To avoid complex questions on the user mailing list ?

IMHO, it's way better to remove such a piece of code, and also remove the setFilters() method, as i'm pretty sure no one use it.

KISS should always be a moto when writing code, unless necessary.

--
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org


Reply via email to