-
-
Notifications
You must be signed in to change notification settings - Fork 236
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
Correctly close resources in BitmapUtils. #440
Conversation
vanniktech
commented
Sep 26, 2022
} | ||
} while (options.inSampleSize <= 512) | ||
|
||
closeSafe(stream) |
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.
There was no try / catch / finally here
} catch (e: OutOfMemoryError) { | ||
options.inSampleSize *= 2 | ||
} | ||
} while (options.inSampleSize <= 512) |
Check warning
Code scanning / detekt
Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers.
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.
Love the simplification and changes, not sure how to test it for the edge cases or catch that was removed and how you checked if the streams didn't keep live.
Besides this, happy with the changes,
return context.contentResolver.openOutputStream(newUri!!, WRITE_AND_TRUNCATE).use { | ||
bitmap.compress(compressFormat, compressQuality, it) | ||
newUri |
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.
What happens here if newUri
is null or the compress
method fails?
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.
val decoder = BitmapRegionDecoder.newInstance(stream!!, false) | ||
do { | ||
|
||
context.contentResolver.openInputStream(uri).use { |
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.
Is this stream closed automatically? I could not find something that guarantee it.
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.
Have you looked at the implementation of use
?
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.
I didn't know the use of the keyword use
either. I just looked it up. This is the given description of use
in kotlin.
Executes the given block function on this resource and then closes it down correctly whether an exception is thrown or not.
Links for more info
@vanniktech I decided to put it here as a reminder for myself instead of closing your PR. I will let it open, and when I understand how to check this stuff and what was wrong first, I review it. |
Why are you so fame addicted? It seriously baffles me. Why isn't the focus of this library to provide good APIs? It's such a hassle contributing to this library in any way. Please correct me if I'm wrong but the description of this pull request clearly shows a stacktrace of StrictMode. You know what that is right? I've even commented the exact line which was the problem - #440 (comment) What else do you need? |
I firmly believe you need to chill a little bit and be more flexible, maybe some time outside can help. Not being ironic or anything to attack you is just a suggestion from someone you don't know, so, of course, feel free to ignore it. Now trying to answer you.
Not sure how to ask you to use a template inside a PR inside a repo no one else will check make me fame addicted.
Not sure how many successful open-source projects you've been able to be part of since day one. For me, this is the first, and I'm learning on the way without much help, but it is working so far
I'm happy to improve the templates and would love some suggestions. What I put in place is what I know can help me yo optimize my time while working on the project. What doesn't apply doesn't need to be filled, of course.
Happy to remove bullshit if you can point me to where it is something that does not need to be done.
Yes, there is something in the library that is not achieving that we could improve?
The nice stuff about OSS is that you can fork and make a better version of it where people will find it better to use it. This would make me happy and remove all my concerns. I can add on the README a link to your fork if you want. I am upset that you feel this way. That's not my goal. But most people get here and just care about what they are passing without thinking about the next and the whole project as OSS community.
No, I don't know what a StrictMode, in this case, is. You can see that I don't know much about stuff, and I'm happy to learn from someone better on the topic than me (you in this case), but I cannot learn assuming a lot of stuff that I don't know. So I need to ask for some more context, or I will spend time studying and investigating. This is not a problem but will make it take longer. Where, since you know, you can share. The template for PRs has 3 points
Without the first, I already make a wrong assessment of the focus of the PR, etc
Believe our issue is that we don't understand each other point of view. That said, I'm in Berlin this week until Thursday, and then I go to Munich for Oktoberfest. It would be nice to catch up if you can Not sure when I will return to this PR. |
My reply was not meant to be an attack in any way. Just straight forward to the point.
It's always about numbers with you - to show a few examples: #439 (comment) Why enforce a template when you get a perfectly valid PR or issue? By enforcing that template and closing issues / PR that don't match your template, you're basically communicating: Thanks but no thanks. (That is the bullshit I'm talking about; always nitpicking) It's the same thing with that bot. There are issues, that are valid and triaged and then that bot wants to autoclose it? Just seems a way to close things out, which reduces number of open issues, which looks 'better'.
A lot. I've tried here #396 and eventually gave up. Being an open source maintainer sucks most of the time. You're 99.9% of the time alone. When you get a contribution, you should be an enabler. Instead you're nit picking about templates. It just seems you're motivated by how many users use this library. And the less time you spend on it the better for you. I do appreciate the time and effort you put into it! I know it's not easy, I have a few open source libraries myself. Regarding strict mode, Google has some documentation: https://developer.android.com/reference/android/os/StrictMode I have a similar snippet in my app and StrictMode crashes since the stream from this library isn't closed properly. How did I fix it? Well, #440 (comment) was the underlying issue and I fixed it with Kotlin's
That's cool! Unfortunately, I'm in Essen at the moment and it's quite far away. |