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.

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.

@kannanjgithub kannanjgithub added the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Sep 15, 2025
@grpc-kokoro grpc-kokoro removed the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Sep 15, 2025
@kannanjgithub kannanjgithub merged commit c1f3287 into grpc:master Sep 15, 2025
17 checks passed
@ejona86
Copy link
Member

ejona86 commented Sep 16, 2025

@Sangamesh1997, please follow our commit message convention (see "Follow typical Git commit message structure" bullet of CONTRIBUTING.md). The "fixes" should have been part of the commit message and really even the "java.security.GeneralSecurityException: Files were unmodified..." error should have been included. Otherwise it isn't clear what "misleading exception" you are talking about.

AgraVator pushed a commit to AgraVator/grpc-java that referenced this pull request Sep 26, 2025
AgraVator pushed a commit to AgraVator/grpc-java that referenced this pull request Sep 26, 2025
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

4 participants