001/*
002 * Copyright 2002-2017 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 *      https://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.core;
018
019import java.io.IOException;
020
021import org.springframework.lang.Nullable;
022
023/**
024 * Subclass of {@link IOException} that properly handles a root cause,
025 * exposing the root cause just like NestedChecked/RuntimeException does.
026 *
027 * <p>Proper root cause handling has not been added to standard IOException before
028 * Java 6, which is why we need to do it ourselves for Java 5 compatibility purposes.
029 *
030 * <p>The similarity between this class and the NestedChecked/RuntimeException
031 * class is unavoidable, as this class needs to derive from IOException.
032 *
033 * @author Juergen Hoeller
034 * @since 2.0
035 * @see #getMessage
036 * @see #printStackTrace
037 * @see org.springframework.core.NestedCheckedException
038 * @see org.springframework.core.NestedRuntimeException
039 */
040@SuppressWarnings("serial")
041public class NestedIOException extends IOException {
042
043        static {
044                // Eagerly load the NestedExceptionUtils class to avoid classloader deadlock
045                // issues on OSGi when calling getMessage(). Reported by Don Brown; SPR-5607.
046                NestedExceptionUtils.class.getName();
047        }
048
049
050        /**
051         * Construct a {@code NestedIOException} with the specified detail message.
052         * @param msg the detail message
053         */
054        public NestedIOException(String msg) {
055                super(msg);
056        }
057
058        /**
059         * Construct a {@code NestedIOException} with the specified detail message
060         * and nested exception.
061         * @param msg the detail message
062         * @param cause the nested exception
063         */
064        public NestedIOException(@Nullable String msg, @Nullable Throwable cause) {
065                super(msg, cause);
066        }
067
068
069        /**
070         * Return the detail message, including the message from the nested exception
071         * if there is one.
072         */
073        @Override
074        @Nullable
075        public String getMessage() {
076                return NestedExceptionUtils.buildMessage(super.getMessage(), getCause());
077        }
078
079}