Skip to content

Adding null checks for instantiating InstrHttpInputStream/InstrHttpOutputStream #3415

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 1 commit into from
Feb 8, 2022

Conversation

raymondlam
Copy link
Member

This should remove the possibility of a null being passed to InstrHttpInputStream/InstrHttpOutputStream.

Fixes #3406

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Feb 7, 2022

Coverage Report 1

Affected Products

  • firebase-perf

    Overall coverage changed from 70.79% (ea9775b) to 70.80% (191a61a) by +0.00%.

    FilenameBase (ea9775b)Merge (191a61a)Diff
    InstrURLConnectionBase.java95.24%94.86%-0.38%

Test Logs

Notes

  • Commit (191a61a) is created by Prow via merging PR base commit (ea9775b) and head commit (c02f4e6).
  • Run gradle <product>:checkCoverage to produce HTML coverage reports locally. After gradle commands finished, report files can be found under <product-build-dir>/reports/jacoco/.

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/XveUtp5nyj.html

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Feb 7, 2022

Size Report 1

Affected Products

  • firebase-perf

    TypeBase (ea9775b)Merge (191a61a)Diff
    aar301 kB301 kB+49 B (+0.0%)
    apk (aggressive)982 kB982 kB+24 B (+0.0%)
    apk (release)2.45 MB2.45 MB+100 B (+0.0%)

Test Logs

Notes

  • Commit (191a61a) is created by Prow via merging PR base commit (ea9775b) and head commit (c02f4e6).

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/L2PRstkVOW.html

@raymondlam
Copy link
Member Author

/test smoke-tests

if (outputStream != null) {
return new InstrHttpOutputStream(outputStream, networkMetricBuilder, timer);
}
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the caller of getOutputStream() okay to deal with null?

Copy link
Member Author

Choose a reason for hiding this comment

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

This question would apply to both input and output stream.

I suspect that it depends on whether the developers thinks a null may occur with getInputStream (but since the docs don't mention it can be null, devs may not add a check).

However, we use this class to wrap the original url connect and call the underlying object as a delegate. We shouldn't be returning our instrumented input stream when the original url connection would have returned a null. If they did not have Firebase Performance, they would have needed to handle the null case anyways.

Copy link
Member Author

@raymondlam raymondlam Feb 7, 2022

Choose a reason for hiding this comment

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

I updated it to return outputStream instead of return null to showcase that we are not changing the original behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense! Thanks!

@raymondlam
Copy link
Member Author

/test smoke-tests

@raymondlam raymondlam merged commit 54d948d into firebase:master Feb 8, 2022
@raymondlam raymondlam deleted the fixNPE_3406 branch February 8, 2022 16:54
@firebase firebase locked and limited conversation to collaborators Mar 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Firebase Performance Plugin Null Pointer Exception While Measuring Network Performance
3 participants