-
Notifications
You must be signed in to change notification settings - Fork 658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Catch security exception in get environment call #1852
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1852 +/- ##
============================================
- Coverage 72.08% 69.74% -2.34%
- Complexity 5126 5532 +406
============================================
Files 473 526 +53
Lines 21970 24449 +2479
Branches 2351 2660 +309
============================================
+ Hits 15838 17053 +1215
- Misses 4925 6089 +1164
- Partials 1207 1307 +100
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can merge this PR create a follow up PR to improve the API.
try { | ||
return System.getenv(name); | ||
} catch (SecurityException e) { | ||
logger.error("Security manager doesn't allow access to the environment variable"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.error("Security manager doesn't allow access to the environment variable"); | |
logger.warn("Security manager doesn't allow access to the environment variable"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.
* the system environment or security manager doesn't allow access to the environment | ||
* variable | ||
*/ | ||
public static String getenv(String name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better have an overload function:
public static String getenv(String name, String def) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
* variable | ||
*/ | ||
public static String getenv(String name) { | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return getenv(name, null);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} catch (SecurityException e) { | ||
logger.warn("Security manager doesn't allow access to the environment variable"); | ||
} | ||
return Collections.unmodifiableMap(new HashMap<>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return Collections.unmodifiableMap(new HashMap<>()); | |
return Collections.emptyMap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
* | ||
* @param name the name of the environment variable | ||
* @param def a default value | ||
* @return the string value of the variable, or {@code null} if the variable is not defined in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @return the string value of the variable, or {@code null} if the variable is not defined in | |
* @return the string value of the variable, or {@code def} if the variable is not defined in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -30,7 +31,9 @@ | |||
import java.util.ArrayList; | |||
import java.util.Collections; | |||
import java.util.Comparator; | |||
import java.util.HashMap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import java.util.HashMap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
* Catch security exception in get environment call * Review changes
Description
Brief description of what this PR is about
This PR is to fix #1848
The customer run into the get environment security issue. This PR put the environment call into a utility function and catch the exception.