jianyun8023 commented on code in PR #22329:
URL: https://github.com/apache/pulsar/pull/22329#discussion_r1536635062


##########
pulsar-common/src/main/java/org/apache/pulsar/common/util/netty/DnsResolverUtil.java:
##########
@@ -39,19 +46,35 @@ public class DnsResolverUtil {
         int ttl = DEFAULT_TTL;
         int negativeTtl = DEFAULT_NEGATIVE_TTL;
         try {
-            // use reflection to call sun.net.InetAddressCachePolicy's get and 
getNegative methods for getting
-            // effective JDK settings for DNS caching
-            Class<?> inetAddressCachePolicyClass = 
Class.forName("sun.net.InetAddressCachePolicy");
-            Method getTTLMethod = inetAddressCachePolicyClass.getMethod("get");
-            ttl = (Integer) getTTLMethod.invoke(null);
-            Method getNegativeTTLMethod = 
inetAddressCachePolicyClass.getMethod("getNegative");
-            negativeTtl = (Integer) getNegativeTTLMethod.invoke(null);
-        } catch (NoSuchMethodException | ClassNotFoundException | 
InvocationTargetException
-                 | IllegalAccessException e) {
+            String ttlStr = Security.getProperty(CACHE_POLICY_PROP);
+            if (ttlStr == null) {
+                // Compatible with sun.net.inetaddr.ttl settings
+                ttlStr = System.getProperty(CACHE_POLICY_PROP_FALLBACK);
+            }
+            String negativeTtlStr = 
Security.getProperty(NEGATIVE_CACHE_POLICY_PROP);
+            if (negativeTtlStr == null) {
+                // Compatible with sun.net.inetaddr.negative.ttl settings
+                negativeTtlStr = 
System.getProperty(NEGATIVE_CACHE_POLICY_PROP_FALLBACK);
+            }
+            ttl = Optional.ofNullable(ttlStr)
+                    .map(Integer::decode)
+                    .filter(i -> i > 0)
+                    .orElseGet(() -> {
+                        if (System.getSecurityManager() == null) {
+                            return JDK_DEFAULT_TTL;
+                        }

Review Comment:
   This issue and the one mentioned above are identical. I can only ensure 
consistency in their implementation approach.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to