/** * Adds an AppenderControl to this set. If this set already contains the element, the call leaves the set unchanged * and returns false. * * @param control The AppenderControl to add. * @return true if this set did not already contain the specified element */ public boolean add(final AppenderControl control) { boolean success; do { final AppenderControl[] original = appenderArray; for (final AppenderControl existing : original) { if (existing.equals(control)) { return false; // the appender is already in the list } } final AppenderControl[] copy = Arrays.copyOf(original, original.length + 1); copy[copy.length - 1] = control; success = appenderArrayUpdater.compareAndSet(this, original, copy); } while (!success); // Could not swap: array was modified by another thread return true; // successfully added }
// AppenderControl is a helper object whose purpose is to make it // easier for LoggerConfig to manage and invoke Appenders. // LoggerConfig manages Appenders by their name. To facilitate this, // two AppenderControl objects are considered equal if and only // if they have the same appender name. @Override public boolean equals(final Object obj) { if (obj == this) { return true; } if (!(obj instanceof AppenderControl)) { return false; } final AppenderControl other = (AppenderControl) obj; return Objects.equals(appenderName, other.appenderName); }q
其equals方法只比较了name,故出现问题