-
Notifications
You must be signed in to change notification settings - Fork 292
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
Prevent errors linked to Security Manager when reading config #7846
Open
vandonr
wants to merge
12
commits into
master
Choose a base branch
from
vandonr/fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3efcbc9
add checks around properties and env variables to avoid crashing if s…
vandonr 5c54fec
do the "orDefault" as well
vandonr 2eccfa6
trying to log config errors later
vandonr 6a36398
exclude utils class from test coverage constraint
vandonr eee8c38
get rid of some linter remarks
vandonr 3a5528c
fix exclusion rule
vandonr afadc51
Merge remote-tracking branch 'origin/master' into vandonr/fix
vandonr fcfeac0
move logging of errors to end of agent.start
vandonr 2c00ffd
change to a single check at the end of the config init
vandonr 9a887d3
remove now unused booleans
vandonr 889fda0
replace System.get in more places
vandonr 316d0e1
Merge remote-tracking branch 'origin/master' into vandonr/fix
vandonr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
internal-api/src/main/java/datadog/trace/util/SystemUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package datadog.trace.util; | ||
|
||
public final class SystemUtils { | ||
|
||
private SystemUtils() {} | ||
|
||
public static String tryGetEnv(String envVar) { | ||
return getEnvOrDefault(envVar, null); | ||
} | ||
|
||
public static String getEnvOrDefault(String envVar, String defaultValue) { | ||
try { | ||
return System.getenv(envVar); | ||
} catch (SecurityException e) { | ||
return defaultValue; | ||
} | ||
} | ||
|
||
public static String tryGetProperty(String property) { | ||
try { | ||
return System.getProperty(property); | ||
} catch (SecurityException e) { | ||
return null; | ||
} | ||
} | ||
|
||
public static String getPropertyOrDefault(String property, String defaultValue) { | ||
try { | ||
return System.getProperty(property, defaultValue); | ||
} catch (SecurityException e) { | ||
return defaultValue; | ||
} | ||
} | ||
|
||
public static boolean canAccessSystemProperties() { | ||
try { | ||
// try to access a common system property and see what happens | ||
System.getProperty("os.name"); | ||
} catch (SecurityException e) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public static boolean canAccessEnvironmentVariables() { | ||
try { | ||
// try to access a common env var and see what happens | ||
System.getenv("DD_ENV"); | ||
} catch (SecurityException e) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could just be
getPropertyOrDefault(property, null)
?