枚举成员在Adwords库中为null

问题描述 投票:1回答:1

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

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

此调用在我的应用程序中抛出空指针异常,特别是.forApi()方法的参数为null。该对象是枚举成员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);
  }

现在,枚举成员如何为空?我该怎么办呢?

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

java spring-boot google-adwords
1个回答
0
投票

找到了。由于版本冲突,Preconditions.checkNotNull投掷了NoSuchMethodError。这阻止了枚举成员被正确初始化,从而保持为空并依次导致NPE。

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

© www.soinside.com 2019 - 2024. All rights reserved.