// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.ui.forms;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import javax.annotation.CheckReturnValue;
import javax.annotation.Detainted;
import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
/**
* Exception thrown when a form field contains a bad value.
*
*
You can safely throw {@code FormFieldException} from within your validator functions, and
* the field name will automatically be propagated into the exception object for you.
*
*
The way that field names work is a bit complicated, because we need to support complex nested
* field names like {@code foo[3].bar}. So what happens is the original exception will be thrown by
* a {@link FormField} validator without the field set. Then as the exception bubbles up the stack,
* it'll be caught by the {@link FormField#convert(Object) convert} method, which then prepends the
* name of that component. Then when the exception reaches the user, the {@link #getFieldName()}
* method will produce the fully-qualified field name.
*
*
This propagation mechanism is also very important when writing
* {@link FormField.Builder#transform(com.google.common.base.Function) transform} functions, which
* oftentimes will not know the name of the field they're validating.
*/
@NotThreadSafe
public final class FormFieldException extends FormException {
private final List