下面列出了怎么用java.lang.NullPointerException的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Returns an input stream for reading the specified resource from the
* the loaded jar files.
*
* The search order is described in the documentation for {@link
* #getResource(String)}.<p>
*
* @param name the resource name
* @return an input stream for reading the resource, or <code>null</code>
* if the resource could not be found
* @since JDK1.1
*/
public InputStream getResourceAsStreamFromJar(String name) {
if (name == null) {
throw new NullPointerException("name");
}
try {
InputStream is = null;
synchronized(syncResourceAsStreamFromJar) {
resourceAsStreamFromJarInCall = true;
// Call super class
is = super.getResourceAsStream(name);
resourceAsStreamFromJarInCall = false;
}
return is;
} catch (Exception e) {
return null;
}
}
/**
* Returns an input stream for reading the specified resource from the
* the loaded jar files.
*
* The search order is described in the documentation for {@link
* #getResource(String)}.<p>
*
* @param name the resource name
* @return an input stream for reading the resource, or <code>null</code>
* if the resource could not be found
* @since JDK1.1
*/
public InputStream getResourceAsStreamFromJar(String name) {
if (name == null) {
throw new NullPointerException("name");
}
try {
InputStream is = null;
synchronized(syncResourceAsStreamFromJar) {
resourceAsStreamFromJarInCall = true;
// Call super class
is = super.getResourceAsStream(name);
resourceAsStreamFromJarInCall = false;
}
return is;
} catch (Exception e) {
return null;
}
}
/**
* Returns an input stream for reading the specified resource from the
* the loaded jar files.
*
* The search order is described in the documentation for {@link
* #getResource(String)}.<p>
*
* @param name the resource name
* @return an input stream for reading the resource, or <code>null</code>
* if the resource could not be found
* @since JDK1.1
*/
public InputStream getResourceAsStreamFromJar(String name) {
if (name == null) {
throw new NullPointerException("name");
}
try {
InputStream is = null;
synchronized(syncResourceAsStreamFromJar) {
resourceAsStreamFromJarInCall = true;
// Call super class
is = super.getResourceAsStream(name);
resourceAsStreamFromJarInCall = false;
}
return is;
} catch (Exception e) {
return null;
}
}
/**
* Returns an input stream for reading the specified resource from the
* the loaded jar files.
*
* The search order is described in the documentation for {@link
* #getResource(String)}.<p>
*
* @param name the resource name
* @return an input stream for reading the resource, or <code>null</code>
* if the resource could not be found
* @since JDK1.1
*/
public InputStream getResourceAsStreamFromJar(String name) {
if (name == null) {
throw new NullPointerException("name");
}
try {
InputStream is = null;
synchronized(syncResourceAsStreamFromJar) {
resourceAsStreamFromJarInCall = true;
// Call super class
is = super.getResourceAsStream(name);
resourceAsStreamFromJarInCall = false;
}
return is;
} catch (Exception e) {
return null;
}
}
/**
* Returns an input stream for reading the specified resource from the
* the loaded jar files.
*
* The search order is described in the documentation for {@link
* #getResource(String)}.<p>
*
* @param name the resource name
* @return an input stream for reading the resource, or <code>null</code>
* if the resource could not be found
* @since JDK1.1
*/
public InputStream getResourceAsStreamFromJar(String name) {
if (name == null) {
throw new NullPointerException("name");
}
try {
InputStream is = null;
synchronized(syncResourceAsStreamFromJar) {
resourceAsStreamFromJarInCall = true;
// Call super class
is = super.getResourceAsStream(name);
resourceAsStreamFromJarInCall = false;
}
return is;
} catch (Exception e) {
return null;
}
}
/**
* Returns an input stream for reading the specified resource from the
* the loaded jar files.
*
* The search order is described in the documentation for {@link
* #getResource(String)}.<p>
*
* @param name the resource name
* @return an input stream for reading the resource, or {@code null}
* if the resource could not be found
* @since 1.1
*/
public InputStream getResourceAsStreamFromJar(String name) {
if (name == null) {
throw new NullPointerException("name");
}
try {
InputStream is = null;
synchronized(syncResourceAsStreamFromJar) {
resourceAsStreamFromJarInCall = true;
// Call super class
is = super.getResourceAsStream(name);
resourceAsStreamFromJarInCall = false;
}
return is;
} catch (Exception e) {
return null;
}
}
/**
* Returns an input stream for reading the specified resource from the
* the loaded jar files.
*
* The search order is described in the documentation for {@link
* #getResource(String)}.<p>
*
* @param name the resource name
* @return an input stream for reading the resource, or <code>null</code>
* if the resource could not be found
* @since JDK1.1
*/
public InputStream getResourceAsStreamFromJar(String name) {
if (name == null) {
throw new NullPointerException("name");
}
try {
InputStream is = null;
synchronized(syncResourceAsStreamFromJar) {
resourceAsStreamFromJarInCall = true;
// Call super class
is = super.getResourceAsStream(name);
resourceAsStreamFromJarInCall = false;
}
return is;
} catch (Exception e) {
return null;
}
}
/**
* Returns an input stream for reading the specified resource from the
* the loaded jar files.
*
* The search order is described in the documentation for {@link
* #getResource(String)}.<p>
*
* @param name the resource name
* @return an input stream for reading the resource, or <code>null</code>
* if the resource could not be found
* @since JDK1.1
*/
public InputStream getResourceAsStreamFromJar(String name) {
if (name == null) {
throw new NullPointerException("name");
}
try {
InputStream is = null;
synchronized(syncResourceAsStreamFromJar) {
resourceAsStreamFromJarInCall = true;
// Call super class
is = super.getResourceAsStream(name);
resourceAsStreamFromJarInCall = false;
}
return is;
} catch (Exception e) {
return null;
}
}
/**
* Returns an input stream for reading the specified resource from the
* the loaded jar files.
*
* The search order is described in the documentation for {@link
* #getResource(String)}.<p>
*
* @param name the resource name
* @return an input stream for reading the resource, or <code>null</code>
* if the resource could not be found
* @since JDK1.1
*/
public InputStream getResourceAsStreamFromJar(String name) {
if (name == null) {
throw new NullPointerException("name");
}
try {
InputStream is = null;
synchronized(syncResourceAsStreamFromJar) {
resourceAsStreamFromJarInCall = true;
// Call super class
is = super.getResourceAsStream(name);
resourceAsStreamFromJarInCall = false;
}
return is;
} catch (Exception e) {
return null;
}
}
/**
* Returns an input stream for reading the specified resource from the
* the loaded jar files.
*
* The search order is described in the documentation for {@link
* #getResource(String)}.<p>
*
* @param name the resource name
* @return an input stream for reading the resource, or <code>null</code>
* if the resource could not be found
* @since JDK1.1
*/
public InputStream getResourceAsStreamFromJar(String name) {
if (name == null) {
throw new NullPointerException("name");
}
try {
InputStream is = null;
synchronized(syncResourceAsStreamFromJar) {
resourceAsStreamFromJarInCall = true;
// Call super class
is = super.getResourceAsStream(name);
resourceAsStreamFromJarInCall = false;
}
return is;
} catch (Exception e) {
return null;
}
}
/**
* Returns an input stream for reading the specified resource from the
* the loaded jar files.
*
* The search order is described in the documentation for {@link
* #getResource(String)}.<p>
*
* @param name the resource name
* @return an input stream for reading the resource, or <code>null</code>
* if the resource could not be found
* @since JDK1.1
*/
public InputStream getResourceAsStreamFromJar(String name) {
if (name == null) {
throw new NullPointerException("name");
}
try {
InputStream is = null;
synchronized(syncResourceAsStreamFromJar) {
resourceAsStreamFromJarInCall = true;
// Call super class
is = super.getResourceAsStream(name);
resourceAsStreamFromJarInCall = false;
}
return is;
} catch (Exception e) {
return null;
}
}
public IncomingTextMessage decrypt(Context context, IncomingTextMessage message)
throws LegacyMessageException, InvalidMessageException, DuplicateMessageException,
NoSessionException, UntrustedIdentityException
{
try {
byte[] decoded = transportDetails.getDecodedMessage(message.getMessageBody().getBytes());
SignalMessage signalMessage = new SignalMessage(decoded);
SessionCipher sessionCipher = new SessionCipher(signalProtocolStore, new SignalProtocolAddress(message.getSender(), 1));
byte[] padded = sessionCipher.decrypt(signalMessage);
byte[] plaintext = transportDetails.getStrippedPaddingMessageBody(padded);
if (message.isEndSession() && "TERMINATE".equals(new String(plaintext))) {
signalProtocolStore.deleteSession(new SignalProtocolAddress(message.getSender(), 1));
}
return message.withMessageBody(new String(plaintext));
} catch (IOException | IllegalArgumentException | NullPointerException e) {
throw new InvalidMessageException(e);
}
}
/**
* Returns an input stream for reading the specified resource from the
* the loaded jar files.
*
* The search order is described in the documentation for {@link
* #getResource(String)}.<p>
*
* @param name the resource name
* @return an input stream for reading the resource, or <code>null</code>
* if the resource could not be found
* @since JDK1.1
*/
public InputStream getResourceAsStreamFromJar(String name) {
if (name == null) {
throw new NullPointerException("name");
}
try {
InputStream is = null;
synchronized(syncResourceAsStreamFromJar) {
resourceAsStreamFromJarInCall = true;
// Call super class
is = super.getResourceAsStream(name);
resourceAsStreamFromJarInCall = false;
}
return is;
} catch (Exception e) {
return null;
}
}
/**
* Returns an input stream for reading the specified resource from the
* the loaded jar files.
*
* The search order is described in the documentation for {@link
* #getResource(String)}.<p>
*
* @param name the resource name
* @return an input stream for reading the resource, or <code>null</code>
* if the resource could not be found
* @since JDK1.1
*/
public InputStream getResourceAsStreamFromJar(String name) {
if (name == null) {
throw new NullPointerException("name");
}
try {
InputStream is = null;
synchronized(syncResourceAsStreamFromJar) {
resourceAsStreamFromJarInCall = true;
// Call super class
is = super.getResourceAsStream(name);
resourceAsStreamFromJarInCall = false;
}
return is;
} catch (Exception e) {
return null;
}
}
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
NullPointerException object1 = new NullPointerException();
harness.check(object1 != null);
harness.check(object1.toString(), "java.lang.NullPointerException");
NullPointerException object2 = new NullPointerException("nothing happens");
harness.check(object2 != null);
harness.check(object2.toString(), "java.lang.NullPointerException: nothing happens");
NullPointerException object3 = new NullPointerException(null);
harness.check(object3 != null);
harness.check(object3.toString(), "java.lang.NullPointerException");
}
@Override
public final NullPointerException listenerCannotBeNull() {
final NullPointerException result = new NullPointerException(String.format(getLoggingLocale(), listenerCannotBeNull$str()));
final StackTraceElement[] st = result.getStackTrace();
result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
return result;
}
@Override
public final NullPointerException nullName() {
final NullPointerException result = new NullPointerException(String.format(getLoggingLocale(), nullName$str()));
final StackTraceElement[] st = result.getStackTrace();
result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
return result;
}
@Override
public final NullPointerException headerNameWasNull() {
final NullPointerException result = new NullPointerException(String.format(getLoggingLocale(), headerNameWasNull$str()));
final StackTraceElement[] st = result.getStackTrace();
result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
return result;
}
@Override
public final NullPointerException paramCannotBeNullNPE(final String name) {
final NullPointerException result = new NullPointerException(String.format(getLoggingLocale(), paramCannotBeNullNPE$str(), name));
final StackTraceElement[] st = result.getStackTrace();
result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
return result;
}
private static void checkNull(int start, int end, int radix) {
int n = 0;
try {
n = Integer.parseInt(null, start, end, radix);
System.err.println("parseInt(null, " + start + ", " + end + ", " + radix +
") incorrectly returned " + n);
throw new RuntimeException();
} catch (NullPointerException npe) {
; // Expected
}
}
public void parseDataLinks(Set<Step> cwlSteps) {
for(Step step: cwlSteps) {
for(InputPort stepInput: step.getInputs()) {
String[] sourcePath = stepInput.getSource().split("/");
String source = sourcePath[sourcePath.length-1];
source = source.replace("#", "");
DataLink dataLink = new DataLink();
SenderPort sender = workflowInputs.get(source);
if(sender == null) {
sender = processorOutputs.get(source);
}
if(sender == null) {
throw new NullPointerException("Cannot find sender port with name: " + source);
}
String receiverId = stepInput.getName();
ReceiverPort receiver = workflowOutputs.get(receiverId);
if(receiver == null) {
receiver = processorInputs.get(receiverId);
}
if(receiver == null) {
throw new NullPointerException("Cannot find receiver port with name: " + receiverId);
}
dataLink.setSendsTo(receiver);
dataLink.setReceivesFrom(sender);
dataLinks.add(dataLink);
}
}
}
/**
* IvParameterSpec(byte[] iv) constructor testing. Checks that
* NullPointerException is thrown in the case of null input
* array and that input array is copied during initialization.
*/
public void testIvParameterSpec1() {
try {
new IvParameterSpec(null);
fail("Should raise an NullPointerException "
+ "in the case of null byte array.");
} catch(NullPointerException e) {
}
byte[] iv = new byte[] {1, 2, 3, 4, 5};
IvParameterSpec ivps = new IvParameterSpec(iv);
iv[0] ++;
assertFalse("The change of input array's content should not cause "
+ "the change of internal array", iv[0] == ivps.getIV()[0]);
}
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
// flag that is set when exception is caught
boolean caught = false;
try {
throw new NullPointerException("NullPointerException");
}
catch (NullPointerException e) {
// correct exception was caught
caught = true;
}
harness.check(caught);
}
/**
* Returns an input stream for reading the specified resource.
*
* The search order is described in the documentation for {@link
* #getResource(String)}.<p>
*
* @param name the resource name
* @return an input stream for reading the resource, or <code>null</code>
* if the resource could not be found
* @since JDK1.1
*/
public InputStream getResourceAsStream(String name)
{
if (name == null) {
throw new NullPointerException("name");
}
try
{
InputStream is = null;
// Fixed #4507227: Slow performance to load
// class and resources. [stanleyh]
//
// The following is used to avoid calling
// AppletClassLoader.findResource() in
// super.getResourceAsStream(). Otherwise,
// unnecessary connection will be made.
//
synchronized(syncResourceAsStream)
{
resourceAsStreamInCall = true;
// Call super class
is = super.getResourceAsStream(name);
resourceAsStreamInCall = false;
}
// 4668479: Option to turn off codebase lookup in AppletClassLoader
// during resource requests. [stanley.ho]
if (codebaseLookup == true && is == null)
{
// If resource cannot be obtained,
// try to download it from codebase
URL url = new URL(base, ParseUtil.encodePath(name, false));
is = url.openStream();
}
return is;
}
catch (Exception e)
{
return null;
}
}
/**
* Returns an input stream for reading the specified resource.
*
* The search order is described in the documentation for {@link
* #getResource(String)}.<p>
*
* @param name the resource name
* @return an input stream for reading the resource, or <code>null</code>
* if the resource could not be found
* @since JDK1.1
*/
public InputStream getResourceAsStream(String name)
{
if (name == null) {
throw new NullPointerException("name");
}
try
{
InputStream is = null;
// Fixed #4507227: Slow performance to load
// class and resources. [stanleyh]
//
// The following is used to avoid calling
// AppletClassLoader.findResource() in
// super.getResourceAsStream(). Otherwise,
// unnecessary connection will be made.
//
synchronized(syncResourceAsStream)
{
resourceAsStreamInCall = true;
// Call super class
is = super.getResourceAsStream(name);
resourceAsStreamInCall = false;
}
// 4668479: Option to turn off codebase lookup in AppletClassLoader
// during resource requests. [stanley.ho]
if (codebaseLookup == true && is == null)
{
// If resource cannot be obtained,
// try to download it from codebase
URL url = new URL(base, ParseUtil.encodePath(name, false));
is = url.openStream();
}
return is;
}
catch (Exception e)
{
return null;
}
}
/**
* Returns an input stream for reading the specified resource.
*
* The search order is described in the documentation for {@link
* #getResource(String)}.<p>
*
* @param name the resource name
* @return an input stream for reading the resource, or <code>null</code>
* if the resource could not be found
* @since JDK1.1
*/
public InputStream getResourceAsStream(String name)
{
if (name == null) {
throw new NullPointerException("name");
}
try
{
InputStream is = null;
// Fixed #4507227: Slow performance to load
// class and resources. [stanleyh]
//
// The following is used to avoid calling
// AppletClassLoader.findResource() in
// super.getResourceAsStream(). Otherwise,
// unnecessary connection will be made.
//
synchronized(syncResourceAsStream)
{
resourceAsStreamInCall = true;
// Call super class
is = super.getResourceAsStream(name);
resourceAsStreamInCall = false;
}
// 4668479: Option to turn off codebase lookup in AppletClassLoader
// during resource requests. [stanley.ho]
if (codebaseLookup == true && is == null)
{
// If resource cannot be obtained,
// try to download it from codebase
URL url = new URL(base, ParseUtil.encodePath(name, false));
is = url.openStream();
}
return is;
}
catch (Exception e)
{
return null;
}
}
/**
* Returns an input stream for reading the specified resource.
*
* The search order is described in the documentation for {@link
* #getResource(String)}.<p>
*
* @param name the resource name
* @return an input stream for reading the resource, or <code>null</code>
* if the resource could not be found
* @since JDK1.1
*/
public InputStream getResourceAsStream(String name)
{
if (name == null) {
throw new NullPointerException("name");
}
try
{
InputStream is = null;
// Fixed #4507227: Slow performance to load
// class and resources. [stanleyh]
//
// The following is used to avoid calling
// AppletClassLoader.findResource() in
// super.getResourceAsStream(). Otherwise,
// unnecessary connection will be made.
//
synchronized(syncResourceAsStream)
{
resourceAsStreamInCall = true;
// Call super class
is = super.getResourceAsStream(name);
resourceAsStreamInCall = false;
}
// 4668479: Option to turn off codebase lookup in AppletClassLoader
// during resource requests. [stanley.ho]
if (codebaseLookup == true && is == null)
{
// If resource cannot be obtained,
// try to download it from codebase
URL url = new URL(base, ParseUtil.encodePath(name, false));
is = url.openStream();
}
return is;
}
catch (Exception e)
{
return null;
}
}
/**
* Returns an input stream for reading the specified resource.
*
* The search order is described in the documentation for {@link
* #getResource(String)}.<p>
*
* @param name the resource name
* @return an input stream for reading the resource, or <code>null</code>
* if the resource could not be found
* @since JDK1.1
*/
public InputStream getResourceAsStream(String name)
{
if (name == null) {
throw new NullPointerException("name");
}
try
{
InputStream is = null;
// Fixed #4507227: Slow performance to load
// class and resources. [stanleyh]
//
// The following is used to avoid calling
// AppletClassLoader.findResource() in
// super.getResourceAsStream(). Otherwise,
// unnecessary connection will be made.
//
synchronized(syncResourceAsStream)
{
resourceAsStreamInCall = true;
// Call super class
is = super.getResourceAsStream(name);
resourceAsStreamInCall = false;
}
// 4668479: Option to turn off codebase lookup in AppletClassLoader
// during resource requests. [stanley.ho]
if (codebaseLookup == true && is == null)
{
// If resource cannot be obtained,
// try to download it from codebase
URL url = new URL(base, ParseUtil.encodePath(name, false));
is = url.openStream();
}
return is;
}
catch (Exception e)
{
return null;
}
}
/**
* Returns an input stream for reading the specified resource.
*
* The search order is described in the documentation for {@link
* #getResource(String)}.<p>
*
* @param name the resource name
* @return an input stream for reading the resource, or {@code null}
* if the resource could not be found
* @since 1.1
*/
public InputStream getResourceAsStream(String name)
{
if (name == null) {
throw new NullPointerException("name");
}
try
{
InputStream is = null;
// Fixed #4507227: Slow performance to load
// class and resources. [stanleyh]
//
// The following is used to avoid calling
// AppletClassLoader.findResource() in
// super.getResourceAsStream(). Otherwise,
// unnecessary connection will be made.
//
synchronized(syncResourceAsStream)
{
resourceAsStreamInCall = true;
// Call super class
is = super.getResourceAsStream(name);
resourceAsStreamInCall = false;
}
// 4668479: Option to turn off codebase lookup in AppletClassLoader
// during resource requests. [stanley.ho]
if (codebaseLookup == true && is == null)
{
// If resource cannot be obtained,
// try to download it from codebase
URL url = new URL(base, ParseUtil.encodePath(name, false));
is = url.openStream();
}
return is;
}
catch (Exception e)
{
return null;
}
}
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseGetNull() {
Optional<Boolean> empty = Optional.empty();
Boolean got = empty.orElseGet(null);
}