aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwisberg <wisberg>2004-01-09 07:21:26 +0000
committerwisberg <wisberg>2004-01-09 07:21:26 +0000
commit4b0e98cb1bad527bf18c5d706ae761bb7003e7f3 (patch)
tree4a03753aeb2ea6e3041c5d2cb734523fa6c72cdf
parente683ed8b8b217808f653a3231a56164ef03a689b (diff)
downloadaspectj-4b0e98cb1bad527bf18c5d706ae761bb7003e7f3.tar.gz
aspectj-4b0e98cb1bad527bf18c5d706ae761bb7003e7f3.zip
NPE instead of IAX for null input, clear out unused code, and update test.
-rw-r--r--bridge/src/org/aspectj/bridge/Message.java57
-rw-r--r--bridge/testsrc/org/aspectj/bridge/MessageTest.java5
2 files changed, 13 insertions, 49 deletions
diff --git a/bridge/src/org/aspectj/bridge/Message.java b/bridge/src/org/aspectj/bridge/Message.java
index 975d0c70d..69ceb0222 100644
--- a/bridge/src/org/aspectj/bridge/Message.java
+++ b/bridge/src/org/aspectj/bridge/Message.java
@@ -28,19 +28,14 @@ import java.util.List;
* Implement messages.
* This implementation is immutable if ISourceLocation is immutable.
*/
-public class Message implements IMessage { // XXX toString or renderer?
+public class Message implements IMessage {
private final String message;
private final IMessage.Kind kind;
private final Throwable thrown;
private final ISourceLocation sourceLocation;
private final String details;
private final List/*SourceLocation*/ extraSourceLocations;
-
- /** convenience for constructing failure messages */
- public static Message fail(String message, Throwable thrown) {
- return new Message(message, IMessage.FAIL, thrown, null);
- }
-
+
/**
* Create a (compiler) error or warning message
* @param message the String used as the underlying message
@@ -67,20 +62,24 @@ public class Message implements IMessage { // XXX toString or renderer?
public Message(String message, String details, IMessage.Kind kind,
ISourceLocation sourceLocation, Throwable thrown, ISourceLocation[] extraSourceLocations) {
this.details = details;
- this.message = (message==null) ? thrown.getMessage() : message;
+ this.message = ((message!=null) ? message : ((thrown==null) ? null : thrown.getMessage()));
this.kind = kind;
this.sourceLocation = sourceLocation;
this.thrown = thrown;
if (extraSourceLocations != null) {
- this.extraSourceLocations = Arrays.asList(extraSourceLocations);
+ this.extraSourceLocations
+ = Collections.unmodifiableList(Arrays.asList(extraSourceLocations));
}
else {
this.extraSourceLocations = Collections.EMPTY_LIST;
}
- if (null == kind) {
+ if (null == this.kind) {
throw new IllegalArgumentException("null kind");
}
+ if (null == this.message) {
+ throw new IllegalArgumentException("null message");
+ }
}
/**
@@ -97,22 +96,6 @@ public class Message implements IMessage { // XXX toString or renderer?
public Message(String message, IMessage.Kind kind, Throwable thrown,
ISourceLocation sourceLocation) {
this(message, "", kind, sourceLocation, thrown, null );
-// this.message = message;
-// this.kind = kind;
-// this.thrown = thrown;
-// this.sourceLocation = sourceLocation;
-// this.details = "";
-// if (null == message) {
-// if (null != thrown) {
-// message = thrown.getMessage();
-// }
-// if (null == message) {
-// throw new IllegalArgumentException("null message");
-// }
-// }
-// if (null == kind) {
-// throw new IllegalArgumentException("null kind");
-// }
}
/** @return the kind of this message */
@@ -172,28 +155,6 @@ public class Message implements IMessage { // XXX toString or renderer?
public String toString() {
return MessageUtil.renderMessage(this,false);
}
-
-
- public static String render(Throwable thrown) { // XXX cf LangUtil.debugStr
- if (null == thrown) return "null throwable";
- Throwable t = null;
- if (thrown instanceof InvocationTargetException) {
- t = ((InvocationTargetException)thrown).getTargetException();
- } else if (thrown instanceof ClassNotFoundException) {
- t = ((ClassNotFoundException) thrown).getException();
- }
- if (null != t) {
- return render(t);
- }
- StringWriter buf = new StringWriter();
- PrintWriter writer = new PrintWriter(buf);
- writer.println(" Message rendering thrown=" + thrown.getClass().getName());
- writer.println(thrown.getMessage());
- thrown.printStackTrace(writer);
- try { buf.close(); }
- catch (IOException ioe) {}
- return buf.getBuffer().toString();
- }
public String getDetails() {
return details;
diff --git a/bridge/testsrc/org/aspectj/bridge/MessageTest.java b/bridge/testsrc/org/aspectj/bridge/MessageTest.java
index 19cbc50ef..2f4482cec 100644
--- a/bridge/testsrc/org/aspectj/bridge/MessageTest.java
+++ b/bridge/testsrc/org/aspectj/bridge/MessageTest.java
@@ -206,6 +206,9 @@ public class MessageTest extends TestCase {
String descriptor, Class exClass) {
try {
IMessage m = make(input, kind, thrown, sourceLocation, descriptor);
+ if ((null == input) && (null != thrown)) {
+ input = thrown.getMessage();
+ }
roundTripCheck(m, input, kind, thrown, sourceLocation);
} catch (AssertionFailedError x) {
throw x;
@@ -219,7 +222,7 @@ public class MessageTest extends TestCase {
Throwable thrown, ISourceLocation sourceLocation) {
IMessage m = message;
assertTrue("not null", null != m);
- assertTrue(""+input, equals(input, m.getMessage()));
+ assertEquals(input, m.getMessage());
assertTrue(""+kind, kind == m.getKind());
assertTrue(""+thrown, equals(thrown, m.getThrown()));
assertTrue(""+sourceLocation,