001/*
002 * Copyright 2012-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.context.properties.source;
018
019import org.springframework.util.Assert;
020
021/**
022 * Exception thrown when a configuration property value is invalid.
023 *
024 * @author Stephane Nicoll
025 * @since 2.0.0
026 */
027@SuppressWarnings("serial")
028public class InvalidConfigurationPropertyValueException extends RuntimeException {
029
030        private final String name;
031
032        private final Object value;
033
034        private final String reason;
035
036        /**
037         * Creates a new instance for the specified property {@code name} and {@code value},
038         * including a {@code reason} why the value is invalid.
039         * @param name the name of the property in canonical format
040         * @param value the value of the property, can be {@code null}
041         * @param reason a human-readable text that describes why the reason is invalid.
042         * Starts with an upper-case and ends with a dots. Several sentences and carriage
043         * returns are allowed.
044         */
045        public InvalidConfigurationPropertyValueException(String name, Object value,
046                        String reason) {
047                super("Property " + name + " with value '" + value + "' is invalid: " + reason);
048                Assert.notNull(name, "Name must not be null");
049                this.name = name;
050                this.value = value;
051                this.reason = reason;
052        }
053
054        /**
055         * Return the name of the property.
056         * @return the property name
057         */
058        public String getName() {
059                return this.name;
060        }
061
062        /**
063         * Return the invalid value, can be {@code null}.
064         * @return the invalid value
065         */
066        public Object getValue() {
067                return this.value;
068        }
069
070        /**
071         * Return the reason why the value is invalid.
072         * @return the reason
073         */
074        public String getReason() {
075                return this.reason;
076        }
077
078}