![](/img/trans.png)
[英]SonarQube rule Classes from “com.sun.*” and “sun.*” packages should not be used
[英]Classes from “com.sun.*” and “sun.*” packages should not be used Sonar issue for Jersey client
我正在使用jersey client
進行休息通話。 我的代碼導入是:
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
一切都很好。 我正在使用Sonar
檢查我的代碼質量。
聲納顯示出一個主要問題:
不應使用“com.sun。 ”和“sun。 ”包中的類
這實際上是使用sun的類嗎?
如果是,有哪些替代方案?
最好遷移到JAX-RS 2.0客戶端類。 但是有些重構是必要的。 請參閱遷移指南 。 例如,如果您之前這樣寫過:
Client client = Client.create();
WebResource webResource = client.resource(restURL).path("myresource/{param}");
String result = webResource.pathParam("param", "value").get(String.class);
你應該像這樣寫:
Client client = ClientFactory.newClient();
WebTarget target = client.target(restURL).path("myresource/{param}");
String result = target.pathParam("param", "value").get(String.class);
因為它們是內部API:它們可能以未記錄或不受支持的方式進行更改,並且它們綁定到特定的JRE / JDK(在您的情況下為Sun),從而限制了程序的可移植性。
盡量避免使用此類API,總是更喜歡公開記錄和指定的類。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.