Skip to content

Conversation

Sangamesh1997
Copy link
Contributor

fixes : #10221
Adds a regression test using reflection on the private readAndUpdate() method to verify that a missing file properly results in a FileNotFoundException.

@@ -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()) {
Copy link
Contributor

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.

Copy link
Contributor Author

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 =
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AdvancedTlsX509TrustManager throws confusing exception if certificate file is missing
2 participants