腾讯 iweibo Java API 1.2.1 bug 修正一处

时间:2021-12-29 04:28:24

发现一腾讯 iweibo Java API Bug,Bug 发生于 iweibo API 函数处在 EJB 内,而在非 EJB(如web应用本身、客户端程序等非远程调用),应该是相同的引用在进行比较,则没有引发错误。

BasicAPI.java 文件内比较字符串必须使用String.equals() 函数,而该文件内对字符串比较却使用"=="符号,作为对象而言,这更类似于地址比较,而不是内容比较,故做修改,具体如下:

 

涉及文件

com.tencent.weibo.api.BasicAPI.java

 

受影响的函数

public BasicAPI(String OAuthVersion);

public BasicAPI(String OAuthVersion, QHttpClient qHttpClient);

 

原实现代码,字符串比较采用“==”符号:

  public BasicAPI(String OAuthVersion){
    if (OAuthVersion == OAuthConstants.OAUTH_VERSION_1 ) {
      requestAPI = new OAuthV1Request();
      apiBaseUrl=APIConstants.API_V1_BASE_URL;
    }else if(OAuthVersion == OAuthConstants.OAUTH_VERSION_2_A){
      requestAPI = new OAuthV2Request();
      apiBaseUrl=APIConstants.API_V2_BASE_URL;
    }
  }
    
  public BasicAPI(String OAuthVersion, QHttpClient qHttpClient){
    if (OAuthVersion == OAuthConstants.OAUTH_VERSION_1  ) {
      requestAPI = new OAuthV1Request(qHttpClient);
      apiBaseUrl=APIConstants.API_V1_BASE_URL;
    }else if(OAuthVersion == OAuthConstants.OAUTH_VERSION_2_A){
      requestAPI = new OAuthV2Request(qHttpClient);
      apiBaseUrl=APIConstants.API_V2_BASE_URL;
    }
  }


 更改后的实现代码,由“==”符号更改为 equals() 函数对字符串进行比较: 

  public BasicAPI(String OAuthVersion){
    if (OAuthVersion.equals(OAuthConstants.OAUTH_VERSION_1) == true){
      requestAPI = new OAuthV1Request();
      apiBaseUrl = APIConstants.API_V1_BASE_URL;
    }
    else if (OAuthVersion.equals(OAuthConstants.OAUTH_VERSION_2_A) == true){
      requestAPI = new OAuthV2Request();
      apiBaseUrl = APIConstants.API_V2_BASE_URL;
    }
  }

  public BasicAPI(String OAuthVersion, QHttpClient qHttpClient){
    if (OAuthVersion.equals(OAuthConstants.OAUTH_VERSION_1) == true){
      requestAPI = new OAuthV1Request(qHttpClient);
      apiBaseUrl = APIConstants.API_V1_BASE_URL;
    }
    else if (OAuthVersion.equals(OAuthConstants.OAUTH_VERSION_2_A) == true){
      requestAPI = new OAuthV2Request(qHttpClient);
      apiBaseUrl = APIConstants.API_V2_BASE_URL;
    }
  }

 

修改完毕后重新编译和打包,发布EJB,Web应用调用正常,Bug处理完毕。

 

Q群讨论:236201801

.