Removed deprecated "MathException".


git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1243473 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gilles Sadowski 2012-02-13 10:35:53 +00:00
parent d429505103
commit 98c3f3b4cf
3 changed files with 3 additions and 327 deletions

View File

@ -1,209 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.commons.math;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.text.MessageFormat;
import java.util.Locale;
import java.util.Set;
import org.apache.commons.math.exception.util.Localizable;
import org.apache.commons.math.exception.util.LocalizedFormats;
/**
* Base class for commons-math checked exceptions.
* <p>
* Supports nesting, emulating JDK 1.4 behavior if necessary.</p>
* <p>
* Adapted from <a href="http://commons.apache.org/collections/api-release/org/apache/commons/collections/FunctorException.html"/>.</p>
*
* @version $Id$
* @deprecated To be removed before 3.0. Please do not use in any new code.
*/
@Deprecated
public class MathException extends Exception {
/** Serializable version identifier. */
private static final long serialVersionUID = 7428019509644517071L;
/** Deprecation message. */
private static final String DEPRECATION_MESSAGE = "This class is deprecated; calling this method is a bug.";
/**
* Pattern used to build the message.
*/
private final Localizable pattern;
/**
* Arguments used to build the message.
*/
private final Object[] arguments;
/**
* Constructs a new <code>MathException</code> with no
* detail message.
*/
public MathException() {
this.pattern = LocalizedFormats.SIMPLE_MESSAGE;
this.arguments = new Object[] { "" };
}
/**
* Constructs a new <code>MathException</code> with specified
* formatted detail message.
* Message formatting is delegated to {@link java.text.MessageFormat}.
* @param pattern format specifier
* @param arguments format arguments
* @since 2.2
*/
public MathException(Localizable pattern, Object ... arguments) {
this.pattern = pattern;
this.arguments = (arguments == null) ? new Object[0] : arguments.clone();
}
/**
* Constructs a new <code>MathException</code> with specified
* nested <code>Throwable</code> root cause.
*
* @param rootCause the exception or error that caused this exception
* to be thrown.
*/
public MathException(Throwable rootCause) {
super(rootCause);
this.pattern = LocalizedFormats.SIMPLE_MESSAGE;
this.arguments = new Object[] { (rootCause == null) ? "" : rootCause.getMessage() };
}
/**
* Constructs a new <code>MathException</code> with specified
* formatted detail message and nested <code>Throwable</code> root cause.
* Message formatting is delegated to {@link java.text.MessageFormat}.
* @param rootCause the exception or error that caused this exception
* to be thrown.
* @param pattern format specifier
* @param arguments format arguments
* @since 2.2
*/
public MathException(Throwable rootCause, Localizable pattern, Object ... arguments) {
super(rootCause);
this.pattern = pattern;
this.arguments = (arguments == null) ? new Object[0] : arguments.clone();
}
/**
* Sets a message.
*
* @param pat Message pattern.
* @param args Values for replacing the placeholders in the message
* pattern.
*/
public void addMessage(Localizable pat,
Object ... args) {
throw new UnsupportedOperationException(DEPRECATION_MESSAGE);
}
/**
* Sets the context (key, value) pair.
* Keys are assumed to be unique within an instance. If the same key is
* assigned a new value, the previous one will be lost.
*
* @param key Context key (not null).
* @param value Context value.
*/
public void setContext(String key, Object value) {
throw new UnsupportedOperationException(DEPRECATION_MESSAGE);
}
/**
* Gets the value associated to the given context key.
*
* @param key Context key.
* @return the context value or {@code null} if the key does not exist.
*/
public Object getContext(String key) {
throw new UnsupportedOperationException(DEPRECATION_MESSAGE);
}
/**
* Gets all the keys stored in the exception
*
* @return the set of keys.
*/
public Set<String> getContextKeys() {
throw new UnsupportedOperationException(DEPRECATION_MESSAGE);
}
/** Gets the message in a specified locale.
*
* @param locale Locale in which the message should be translated
*
* @return localized message
* @since 1.2
*/
public String getMessage(final Locale locale) {
if (pattern != null) {
return new MessageFormat(pattern.getLocalizedString(locale), locale).format(arguments);
}
return "";
}
/**
* Gets the message in a conventional US locale.
*
* @return localized message
*/
@Override
public String getMessage() {
return getMessage(Locale.US);
}
/**
* Gets the message in the system default locale.
*
* @return localized message
*/
@Override
public String getLocalizedMessage() {
return getMessage(Locale.getDefault());
}
/**
* Prints the stack trace of this exception to the standard error stream.
*/
@Override
public void printStackTrace() {
printStackTrace(System.err);
}
/**
* Prints the stack trace of this exception to the specified stream.
*
* @param out the <code>PrintStream</code> to use for output
*/
@Override
public void printStackTrace(PrintStream out) {
synchronized (out) {
PrintWriter pw = new PrintWriter(out, false);
printStackTrace(pw);
// Flush the PrintWriter before it's GC'ed.
pw.flush();
}
}
}

View File

@ -52,6 +52,9 @@ The <action> type attribute can be add,update,fix,remove.
If the output is not quite correct, check for invisible trailing spaces!
-->
<release version="3.0" date="TBD" description="TBD">
<action dev="erans" type="update" issue="MATH-488">
Removed "MathException" (from package "o.a.c.math").
</action>
<action dev="erans" type="update" issue="MATH-459">
Removed "MathRuntimeException" (from package "o.a.c.math").
</action>

View File

@ -1,118 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.commons.math;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Locale;
import org.apache.commons.math.exception.MathIllegalStateException;
import org.apache.commons.math.exception.util.DummyLocalizable;
import org.apache.commons.math.exception.util.Localizable;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.junit.Assert;
import org.junit.Test;
/**
* @version $Id$
*/
public class MathExceptionTest {
@Test
public void testConstructor(){
MathException ex = new MathException();
Assert.assertNull(ex.getCause());
Assert.assertEquals("", ex.getMessage());
Assert.assertEquals("", ex.getMessage(Locale.FRENCH));
}
@Test
public void testConstructorCause(){
String inMsg = "inner message";
Exception cause = new Exception(inMsg);
MathException ex = new MathException(cause);
Assert.assertEquals(cause, ex.getCause());
}
/**
* Tests the printStackTrace() operation.
*/
@Test
public void testPrintStackTrace() {
Localizable outMsg = new DummyLocalizable("outer message");
Localizable inMsg = new DummyLocalizable("inner message");
MathIllegalStateException cause = new MathIllegalStateException(LocalizedFormats.SIMPLE_MESSAGE, inMsg);
MathException ex = new MathException(cause, outMsg);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
ex.printStackTrace(ps);
String stack = baos.toString();
String outerMsg = "org.apache.commons.math.MathException: outer message";
String innerMsg = "Caused by: " +
"org.apache.commons.math.exception.MathIllegalStateException: inner message";
Assert.assertTrue(stack.startsWith(outerMsg));
Assert.assertTrue(stack.indexOf(innerMsg) > 0);
PrintWriter pw = new PrintWriter(ps, true);
ex.printStackTrace(pw);
stack = baos.toString();
Assert.assertTrue(stack.startsWith(outerMsg));
Assert.assertTrue(stack.indexOf(innerMsg) > 0);
}
/**
* Test serialization
*/
@Test
public void testSerialization() {
Localizable outMsg = new DummyLocalizable("outer message");
Localizable inMsg = new DummyLocalizable("inner message");
MathIllegalStateException cause = new MathIllegalStateException(LocalizedFormats.SIMPLE_MESSAGE, inMsg);
MathException ex = new MathException(cause, outMsg);
MathException image = (MathException) TestUtils.serializeAndRecover(ex);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
ex.printStackTrace(ps);
String stack = baos.toString();
ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
PrintStream ps2 = new PrintStream(baos2);
image.printStackTrace(ps2);
String stack2 = baos2.toString();
// See if JDK supports nested exceptions. If not, stack trace of
// inner exception will not be serialized
boolean jdkSupportsNesting = false;
try {
Throwable.class.getDeclaredMethod("getCause", new Class[0]);
jdkSupportsNesting = true;
} catch (NoSuchMethodException e) {
jdkSupportsNesting = false;
}
if (jdkSupportsNesting) {
Assert.assertEquals(stack, stack2);
} else {
Assert.assertTrue(stack2.indexOf(inMsg.getSourceString()) != -1);
Assert.assertTrue(stack2.indexOf("MathConfigurationException") != -1);
}
}
}