Adwords 库中的枚举成员 null

Enum member null in Adwords library

我正在使用 Google Adwords 库。要创建凭证,提供了构建器模式:

new OfflineCredentials.Builder()
                      .forApi(OfflineCredentials.Api.ADWORDS)
                      .fromFile("D:\...\ads.properties")
                      .build()

此调用在我的应用程序中抛出空指针异常,特别是 .forApi() 方法的参数为空。该对象是枚举成员 defined thus:

 public static enum Api implements OAuthConfig {
  ADWORDS("api.adwords.", "https://www.googleapis.com/auth/adwords"),
  AD_MANAGER("api.admanager.", "https://www.googleapis.com/auth/dfp");

  private final String propKeyPrefix;
  private final String scope;

  private Api(String propKeyPrefix, String scope) {
    this.propKeyPrefix =
        Preconditions.checkNotNull(propKeyPrefix, "Null property key prefix for: %s", this);
    this.scope = Preconditions.checkNotNull(scope, "Null scope for: %s", this);
  }

现在,枚举成员怎么可能为空?我该怎么办?

这是 class 加载的问题吗?如果有帮助,它是一个 Spring 启动应用程序。

找到了。由于版本冲突,Preconditions.checkNotNull 抛出了 NoSuchMethodError。这阻止了枚举成员被正确初始化,从而保持 null 并反过来导致 NPE。

TIL:当枚举成员为 null 时,其构造函数中确实存在错误。