-
Notifications
You must be signed in to change notification settings - Fork 4
Fix potential null pointer exceptions #159
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
63d003d
Fix potential null pointer exceptions
giarc3 5877ccd
Add NullParsingValidator interface instead
giarc3 508ed33
Switch to abstract class so it can be package-private
giarc3 68762ab
Self review
giarc3 c09a092
Address feedback
giarc3 28fd822
Comment
giarc3 9c4a3fb
Add a newline
coltfred 96c1978
Missed a file
giarc3 19cd698
Wrap the IllegalArgumentException
giarc3 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
8 changes: 8 additions & 0 deletions
8
src/main/java/com/ironcorelabs/tenantsecurity/kms/v1/NullParsingValidator.java
This file contains hidden or 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,8 @@ | ||
| package com.ironcorelabs.tenantsecurity.kms.v1; | ||
|
|
||
| abstract class NullParsingValidator { | ||
| /** | ||
| * Throws an IllegalArgumentException if any of the fields were parsed as null. | ||
| */ | ||
| abstract void ensureNoNullsOrThrow() throws IllegalArgumentException; | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
52 changes: 52 additions & 0 deletions
52
src/test/java/com/ironcorelabs/tenantsecurity/kms/v1/JsonParsingTest.java
This file contains hidden or 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,52 @@ | ||
| package com.ironcorelabs.tenantsecurity.kms.v1; | ||
|
|
||
| import java.io.StringReader; | ||
| import org.testng.annotations.Test; | ||
| import com.google.api.client.json.JsonObjectParser; | ||
| import com.google.api.client.json.gson.GsonFactory; | ||
|
|
||
| @Test(groups = {"unit"}) | ||
| public class JsonParsingTest { | ||
| static JsonObjectParser parser = new JsonObjectParser(new GsonFactory()); | ||
|
|
||
| @Test(expectedExceptions = IllegalArgumentException.class) | ||
| void batchKeysErrors() throws Exception { | ||
| String json = "{}"; | ||
| BatchWrappedDocumentKeys type = parser.<BatchWrappedDocumentKeys>parseAndClose( | ||
| new StringReader(json), BatchWrappedDocumentKeys.class); | ||
| type.ensureNoNullsOrThrow(); | ||
| } | ||
|
|
||
| @Test(expectedExceptions = IllegalArgumentException.class) | ||
| void derivedKeyResponseErrors() throws Exception { | ||
| String json = "{}"; | ||
| DeriveKeyResponse type = | ||
| parser.<DeriveKeyResponse>parseAndClose(new StringReader(json), DeriveKeyResponse.class); | ||
| type.ensureNoNullsOrThrow(); | ||
|
|
||
| } | ||
|
|
||
| @Test(expectedExceptions = IllegalArgumentException.class) | ||
| void unwrappedDocumentKeyErrors() throws Exception { | ||
| String json = "{}"; | ||
| UnwrappedDocumentKey type = parser.<UnwrappedDocumentKey>parseAndClose(new StringReader(json), | ||
| UnwrappedDocumentKey.class); | ||
| type.ensureNoNullsOrThrow(); | ||
| } | ||
|
|
||
| @Test(expectedExceptions = IllegalArgumentException.class) | ||
| void wrappedDocumentKeyErrors() throws Exception { | ||
| String json = "{}"; | ||
| WrappedDocumentKey type = | ||
| parser.<WrappedDocumentKey>parseAndClose(new StringReader(json), WrappedDocumentKey.class); | ||
| type.ensureNoNullsOrThrow(); | ||
| } | ||
|
|
||
| @Test(expectedExceptions = IllegalArgumentException.class) | ||
| void rekeyedDocumentKeyErrors() throws Exception { | ||
| String json = "{}"; | ||
| RekeyedDocumentKey type = | ||
| parser.<RekeyedDocumentKey>parseAndClose(new StringReader(json), RekeyedDocumentKey.class); | ||
| type.ensureNoNullsOrThrow(); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,4 @@ | ||
| #!/bin/bash | ||
| # Be sure to set API_KEY, TENANT_ID, and NEW_TENANT_ID env vars | ||
| cd "${0%/*/*}" # set the current directory to the one above this script | ||
| mvn -Dsuite=test-suites/test-all test |
This file contains hidden or 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,18 @@ | ||
| <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> | ||
|
|
||
| <suite name="allTests"> | ||
| <test name="allTests"> | ||
| <groups> | ||
| <run> | ||
| <include name="unit" /> | ||
| <include name="local-integration" /> | ||
| <include name="dev-integration" /> | ||
| <include name="local-batch-integration" /> | ||
| <include name="local-deterministic" /> | ||
| </run> | ||
| </groups> | ||
| <packages> | ||
| <package name=".*" /> | ||
| </packages> | ||
| </test> | ||
| </suite> |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.