npe() runtime intrinsic method.
This commit is contained in:
@@ -10,4 +10,14 @@ public class Intrinsics {
|
||||
public static String stringPlus(String self, Object other) {
|
||||
return ((self == null) ? "null" : self) + ((other == null) ? "null" : other.toString());
|
||||
}
|
||||
|
||||
public static Object npe(Object self) {
|
||||
if(self == null)
|
||||
return throwNpe();
|
||||
return self;
|
||||
}
|
||||
|
||||
private static Object throwNpe() {
|
||||
throw new JetNullPointerException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package jet.runtime;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
class JetNullPointerException extends NullPointerException {
|
||||
@Override
|
||||
public synchronized Throwable fillInStackTrace() {
|
||||
super.fillInStackTrace();
|
||||
StackTraceElement[] stackTrace = getStackTrace();
|
||||
ArrayList<StackTraceElement> list = new ArrayList<StackTraceElement>();
|
||||
boolean skip = true;
|
||||
for(StackTraceElement ste : stackTrace) {
|
||||
if(!skip) {
|
||||
list.add(ste);
|
||||
}
|
||||
else {
|
||||
if("jet.runtime.Intrinsics".equals(ste.getClassName()) && "npe".equals(ste.getMethodName())) {
|
||||
skip = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
setStackTrace(list.toArray(new StackTraceElement[list.size()]));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Intrinsics.npe(null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user