Skip to content

Commit

Permalink
Merge pull request #40 from chuntaojun/fix_err_log
Browse files Browse the repository at this point in the history
fix: 修复 pickAddress 出现数组越界问题
  • Loading branch information
andrewshan authored Aug 24, 2022
2 parents e7f6514 + fb155d1 commit f9719a8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.time.Duration;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
Expand All @@ -46,9 +47,8 @@ public static String pickAddress(List<String> addresses) {
if (addresses.size() == 1) {
return addresses.get(0);
}
Random random = new Random();
int i = random.nextInt();
return addresses.get(i % addresses.size());
int i = ThreadLocalRandom.current().nextInt(addresses.size());
return addresses.get(i);
}

public <T> RestResponse<T> curlRemoteEndpoint(String url, HttpMethod method,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import cn.polarismesh.polaris.sync.registry.utils.ConfigUtils;
import com.tencent.polaris.client.pb.ResponseProto.DiscoverResponse;
import com.tencent.polaris.client.pb.ServiceProto.Instance;
import java.io.ByteArrayInputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -86,7 +89,10 @@ public void run() {
}
}
} catch (Throwable e) {
LOG.error("[Core] pull task(source {}) encounter exception", source.getName(), e);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
LOG.error("[Core] pull task(source {}) encounter exception {}", source.getName(), sw);
}
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</scm>

<properties>
<revision>0.2.0-alpha.1</revision>
<revision>0.2.0-alpha.2</revision>
<timestamp>${maven.build.timestamp}</timestamp>
<!-- Spring Cloud -->
<spring.cloud.version>2021.0.3</spring.cloud.version>
Expand Down

0 comments on commit f9719a8

Please sign in to comment.