In my opinion,the line 176 [if (processorConstructor == null) ] is redundant, because if processorConstructor is null, a NullPointerException should be trowed previously. So, I think we should remove the redundant code here. Of course, maybe there are any other things that i haven't knew about, and who knows?
the version I talked about is Mina 2, and follow is the version infomation: ste...@stefan:~/Mina/trunk$ svn info Path: . URL: http://svn.apache.org/repos/asf/mina/trunk Repository Root: http://svn.apache.org/repos/asf Repository UUID: 13f79535-47bb-0310-9956-ffa450edef68 Revision: 885194 Node Kind: directory Schedule: normal Last Changed Author: elecharny Last Changed Rev: 884479 Last Changed Date: 2009-11-26 17:41:32 +0800 (四, 26 11月 2009) @SuppressWarnings("unchecked") public SimpleIoProcessorPool(Class<? extends IoProcessor<T>> processorType, Executor executor, int size) { if (processorType == null) { throw new NullPointerException("processorType"); } if (size <= 0) { throw new IllegalArgumentException("size: " + size + " (expected: positive integer)"); } if (executor == null) { this.executor = executor = Executors.newCachedThreadPool(); this.createdExecutor = true; } else { this.executor = executor; this.createdExecutor = false; } pool = new IoProcessor[size]; boolean success = false; Constructor<? extends IoProcessor<T>> processorConstructor = null; boolean usesExecutorArg = true; try { // We create at least one processor try { try { processorConstructor = processorType .getConstructor(ExecutorService.class); pool[0] = processorConstructor.newInstance(executor); } catch (NoSuchMethodException e) { // To the next step... } try { processorConstructor = processorType .getConstructor(Executor.class); pool[0] = processorConstructor.newInstance(executor); } catch (NoSuchMethodException e) { // To the next step... } try { processorConstructor = processorType.getConstructor(); usesExecutorArg = false; pool[0] = processorConstructor.newInstance(); } catch (NoSuchMethodException e) { // To the next step... } } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeIoException( "Failed to create a new instance of " + processorType.getName(), e); } // here , maybe itis redundant if (processorConstructor == null) { // Raise an exception if no proper constructor is found. throw new IllegalArgumentException(String .valueOf(processorType) + " must have a public constructor " + "with one " + ExecutorService.class.getSimpleName() + " parameter, " + "a public constructor with one " + Executor.class.getSimpleName() + " parameter or a public default constructor."); } // Constructor found now use it for all subsequent instantiations for (int i = 1; i < pool.length; i++) { try { if (usesExecutorArg) { pool[i] = processorConstructor.newInstance(executor); } else { pool[i] = processorConstructor.newInstance(); } } catch (Exception e) { // Won't happen because it has been done previously } } success = true; } finally { if (!success) { dispose(); } } } Stefan Lee(李鹏) Huazhong University of Science and Technology
