-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Fix misleading exception in AdvancedTlsX509TrustManager when cert file is missing #12353
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
base: master
Are you sure you want to change the base?
Conversation
@@ -339,6 +340,9 @@ public void run() { | |||
private long readAndUpdate(File trustCertFile, long oldTime) | |||
throws IOException, GeneralSecurityException { | |||
long newTime = checkNotNull(trustCertFile, "trustCertFile").lastModified(); | |||
if (newTime == 0 && !trustCertFile.exists()) { |
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.
The check for !trustCertFile.exists() is redundant. See documentation for File.lastModified - 0 means file doesn't exist or an IO exception occurred. The exception we throw should say Certificate not found or not readable.
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.
@kannanjgithub Thanks for the feedback, I understand your point, to change this will removing the redundant trustCertFile.exists() check and throwing an appropriate IOException with message like "Certificate not found or not readable".
@Test | ||
public void missingFile_throwsFileNotFoundException() throws Exception { | ||
AdvancedTlsX509TrustManager trustManager = AdvancedTlsX509TrustManager.newBuilder().build(); | ||
Method readAndUpdateMethod = |
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 should not be calling the private method via reflection. Use the public method that calls it internally.
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.
Noted.
fixes : #10221
Adds a regression test using reflection on the private readAndUpdate() method to verify that a missing file properly results in a FileNotFoundException.