java.lang.NullPointerException.initCause()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(235)

本文整理了Java中java.lang.NullPointerException.initCause()方法的一些代码示例,展示了NullPointerException.initCause()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NullPointerException.initCause()方法的具体详情如下:
包路径:java.lang.NullPointerException
类名称:NullPointerException
方法名:initCause

NullPointerException.initCause介绍

暂无

代码示例

代码示例来源:origin: ReactiveX/RxJava

/**
 * Creates a NullPointerException instance and sets the given Throwable as its initial cause.
 * @param ex the Throwable instance to use as cause, not null (not verified)
 * @return the created NullPointerException
 */
private static NullPointerException toNpe(Throwable ex) {
  NullPointerException npe = new NullPointerException("Actually not, but can't pass out an exception otherwise...");
  npe.initCause(ex);
  return npe;
}

代码示例来源:origin: redisson/redisson

/**
 * Creates a NullPointerException instance and sets the given Throwable as its initial cause.
 * @param ex the Throwable instance to use as cause, not null (not verified)
 * @return the created NullPointerException
 */
private static NullPointerException toNpe(Throwable ex) {
  NullPointerException npe = new NullPointerException("Actually not, but can't pass out an exception otherwise...");
  npe.initCause(ex);
  return npe;
}

代码示例来源:origin: ReactiveX/RxJava

@Override
  public void subscribeActual(Subscriber<? super R> s) {
    try {
      Subscriber<? super T> st = operator.apply(s);

      if (st == null) {
        throw new NullPointerException("Operator " + operator + " returned a null Subscriber");
      }

      source.subscribe(st);
    } catch (NullPointerException e) { // NOPMD
      throw e;
    } catch (Throwable e) {
      Exceptions.throwIfFatal(e);
      // can't call onError because no way to know if a Subscription has been set or not
      // can't call onSubscribe because the call might have set a Subscription already
      RxJavaPlugins.onError(e);

      NullPointerException npe = new NullPointerException("Actually not, but can't throw other exceptions due to RS");
      npe.initCause(e);
      throw npe;
    }
  }
}

代码示例来源:origin: apache/avro

/** Helper method for adding a message to an NPE. */
protected NullPointerException npe(NullPointerException e, String s) {
 NullPointerException result = new NullPointerException(e.getMessage()+s);
 result.initCause(e.getCause() == null ? e : e.getCause());
 return result;
}

代码示例来源:origin: org.apache.avro/avro

/** Helper method for adding a message to an NPE. */
protected NullPointerException npe(NullPointerException e, String s) {
 NullPointerException result = new NullPointerException(e.getMessage()+s);
 result.initCause(e.getCause() == null ? e : e.getCause());
 return result;
}

代码示例来源:origin: ReactiveX/RxJava

@Override
  public void subscribeActual(Observer<? super R> observer) {
    Observer<? super T> liftedObserver;
    try {
      liftedObserver = ObjectHelper.requireNonNull(operator.apply(observer), "Operator " + operator + " returned a null Observer");
    } catch (NullPointerException e) { // NOPMD
      throw e;
    } catch (Throwable e) {
      Exceptions.throwIfFatal(e);
      // can't call onError because no way to know if a Disposable has been set or not
      // can't call onSubscribe because the call might have set a Disposable already
      RxJavaPlugins.onError(e);

      NullPointerException npe = new NullPointerException("Actually not, but can't throw other exceptions due to RS");
      npe.initCause(e);
      throw npe;
    }

    source.subscribe(liftedObserver);
  }
}

代码示例来源:origin: redisson/redisson

@Override
  public void subscribeActual(Subscriber<? super R> s) {
    try {
      Subscriber<? super T> st = operator.apply(s);

      if (st == null) {
        throw new NullPointerException("Operator " + operator + " returned a null Subscriber");
      }

      source.subscribe(st);
    } catch (NullPointerException e) { // NOPMD
      throw e;
    } catch (Throwable e) {
      Exceptions.throwIfFatal(e);
      // can't call onError because no way to know if a Subscription has been set or not
      // can't call onSubscribe because the call might have set a Subscription already
      RxJavaPlugins.onError(e);

      NullPointerException npe = new NullPointerException("Actually not, but can't throw other exceptions due to RS");
      npe.initCause(e);
      throw npe;
    }
  }
}

代码示例来源:origin: ReactiveX/RxJava

@SchedulerSupport(SchedulerSupport.NONE)
@Override
public final void subscribe(SingleObserver<? super T> observer) {
  ObjectHelper.requireNonNull(observer, "subscriber is null");
  observer = RxJavaPlugins.onSubscribe(this, observer);
  ObjectHelper.requireNonNull(observer, "The RxJavaPlugins.onSubscribe hook returned a null SingleObserver. Please check the handler provided to RxJavaPlugins.setOnSingleSubscribe for invalid null returns. Further reading: https://github.com/ReactiveX/RxJava/wiki/Plugins");
  try {
    subscribeActual(observer);
  } catch (NullPointerException ex) {
    throw ex;
  } catch (Throwable ex) {
    Exceptions.throwIfFatal(ex);
    NullPointerException npe = new NullPointerException("subscribeActual failed");
    npe.initCause(ex);
    throw npe;
  }
}

代码示例来源:origin: ReactiveX/RxJava

@SchedulerSupport(SchedulerSupport.NONE)
@Override
public final void subscribe(MaybeObserver<? super T> observer) {
  ObjectHelper.requireNonNull(observer, "observer is null");
  observer = RxJavaPlugins.onSubscribe(this, observer);
  ObjectHelper.requireNonNull(observer, "The RxJavaPlugins.onSubscribe hook returned a null MaybeObserver. Please check the handler provided to RxJavaPlugins.setOnMaybeSubscribe for invalid null returns. Further reading: https://github.com/ReactiveX/RxJava/wiki/Plugins");
  try {
    subscribeActual(observer);
  } catch (NullPointerException ex) {
    throw ex;
  } catch (Throwable ex) {
    Exceptions.throwIfFatal(ex);
    NullPointerException npe = new NullPointerException("subscribeActual failed");
    npe.initCause(ex);
    throw npe;
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Override
public void onError(Throwable t) {
  T v;
  try {
    v = valueSupplier.apply(t);
  } catch (Throwable e) {
    Exceptions.throwIfFatal(e);
    downstream.onError(new CompositeException(t, e));
    return;
  }
  if (v == null) {
    NullPointerException e = new NullPointerException("The supplied value is null");
    e.initCause(t);
    downstream.onError(e);
    return;
  }
  downstream.onNext(v);
  downstream.onComplete();
}

代码示例来源:origin: ReactiveX/RxJava

@SchedulerSupport(SchedulerSupport.NONE)
@Override
public final void subscribe(Observer<? super T> observer) {
  ObjectHelper.requireNonNull(observer, "observer is null");
  try {
    observer = RxJavaPlugins.onSubscribe(this, observer);
    ObjectHelper.requireNonNull(observer, "The RxJavaPlugins.onSubscribe hook returned a null Observer. Please change the handler provided to RxJavaPlugins.setOnObservableSubscribe for invalid null returns. Further reading: https://github.com/ReactiveX/RxJava/wiki/Plugins");
    subscribeActual(observer);
  } catch (NullPointerException e) { // NOPMD
    throw e;
  } catch (Throwable e) {
    Exceptions.throwIfFatal(e);
    // can't call onError because no way to know if a Disposable has been set or not
    // can't call onSubscribe because the call might have set a Subscription already
    RxJavaPlugins.onError(e);
    NullPointerException npe = new NullPointerException("Actually not, but can't throw other exceptions due to RS");
    npe.initCause(e);
    throw npe;
  }
}

代码示例来源:origin: redisson/redisson

@Override
  public void subscribeActual(Observer<? super R> s) {
    Observer<? super T> observer;
    try {
      observer = ObjectHelper.requireNonNull(operator.apply(s), "Operator " + operator + " returned a null Observer");
    } catch (NullPointerException e) { // NOPMD
      throw e;
    } catch (Throwable e) {
      Exceptions.throwIfFatal(e);
      // can't call onError because no way to know if a Disposable has been set or not
      // can't call onSubscribe because the call might have set a Disposable already
      RxJavaPlugins.onError(e);

      NullPointerException npe = new NullPointerException("Actually not, but can't throw other exceptions due to RS");
      npe.initCause(e);
      throw npe;
    }

    source.subscribe(observer);
  }
}

代码示例来源:origin: redisson/redisson

@SchedulerSupport(SchedulerSupport.NONE)
@Override
public final void subscribe(MaybeObserver<? super T> observer) {
  ObjectHelper.requireNonNull(observer, "observer is null");
  observer = RxJavaPlugins.onSubscribe(this, observer);
  ObjectHelper.requireNonNull(observer, "observer returned by the RxJavaPlugins hook is null");
  try {
    subscribeActual(observer);
  } catch (NullPointerException ex) {
    throw ex;
  } catch (Throwable ex) {
    Exceptions.throwIfFatal(ex);
    NullPointerException npe = new NullPointerException("subscribeActual failed");
    npe.initCause(ex);
    throw npe;
  }
}

代码示例来源:origin: redisson/redisson

@SchedulerSupport(SchedulerSupport.NONE)
@Override
public final void subscribe(SingleObserver<? super T> subscriber) {
  ObjectHelper.requireNonNull(subscriber, "subscriber is null");
  subscriber = RxJavaPlugins.onSubscribe(this, subscriber);
  ObjectHelper.requireNonNull(subscriber, "subscriber returned by the RxJavaPlugins hook is null");
  try {
    subscribeActual(subscriber);
  } catch (NullPointerException ex) {
    throw ex;
  } catch (Throwable ex) {
    Exceptions.throwIfFatal(ex);
    NullPointerException npe = new NullPointerException("subscribeActual failed");
    npe.initCause(ex);
    throw npe;
  }
}

代码示例来源:origin: redisson/redisson

@Override
public void onError(Throwable e) {
  CompletableSource c;
  try {
    c = errorMapper.apply(e);
  } catch (Throwable ex) {
    Exceptions.throwIfFatal(ex);
    s.onError(new CompositeException(ex, e));
    return;
  }
  if (c == null) {
    NullPointerException npe = new NullPointerException("The CompletableConsumable returned is null");
    npe.initCause(e);
    s.onError(npe);
    return;
  }
  c.subscribe(new OnErrorObserver());
}

代码示例来源:origin: redisson/redisson

@Override
public void onError(Throwable t) {
  T v;
  try {
    v = valueSupplier.apply(t);
  } catch (Throwable e) {
    Exceptions.throwIfFatal(e);
    actual.onError(new CompositeException(t, e));
    return;
  }
  if (v == null) {
    NullPointerException e = new NullPointerException("The supplied value is null");
    e.initCause(t);
    actual.onError(e);
    return;
  }
  actual.onNext(v);
  actual.onComplete();
}

代码示例来源:origin: redisson/redisson

@SchedulerSupport(SchedulerSupport.NONE)
@Override
public final void subscribe(Observer<? super T> observer) {
  ObjectHelper.requireNonNull(observer, "observer is null");
  try {
    observer = RxJavaPlugins.onSubscribe(this, observer);
    ObjectHelper.requireNonNull(observer, "Plugin returned null Observer");
    subscribeActual(observer);
  } catch (NullPointerException e) { // NOPMD
    throw e;
  } catch (Throwable e) {
    Exceptions.throwIfFatal(e);
    // can't call onError because no way to know if a Disposable has been set or not
    // can't call onSubscribe because the call might have set a Subscription already
    RxJavaPlugins.onError(e);
    NullPointerException npe = new NullPointerException("Actually not, but can't throw other exceptions due to RS");
    npe.initCause(e);
    throw npe;
  }
}

代码示例来源:origin: ReactiveX/RxJava

npe.initCause(t);
downstream.onError(npe);
return;

代码示例来源:origin: ReactiveX/RxJava

npe.initCause(e);
throw npe;

代码示例来源:origin: redisson/redisson

npe.initCause(t);
actual.onError(npe);
return;

相关文章