Skip to content
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

False Positive on "Dls dead local store" #63

Closed
jcnoriega opened this issue Dec 1, 2015 · 5 comments
Closed

False Positive on "Dls dead local store" #63

jcnoriega opened this issue Dec 1, 2015 · 5 comments

Comments

@jcnoriega
Copy link

Hi there! It appears i have a false positive on this warning. In my Android project, I try to make a file where i'm going to store some profile pictures. I'm doing this on a singleton service, inside a static method:

private static File createCameraImageFile() throws IOException {
        final String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
        final String cameraPhotoFileName = String.format("UMW_PROFILE_%1$s.jpeg", timeStamp);
        final File storageDir = Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_PICTURES);
        return new File(storageDir, cameraPhotoFileName);
    }

The warning says I have a dead local store on cameraPhotoName. I tried deleting the variable and just put it directly in the return, like this:

private static File createCameraImageFile() throws IOException {
        final String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
        final File storageDir = Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_PICTURES);
        return new File(storageDir, String.format("UMW_PROFILE_%1$s.jpeg", timeStamp));

But it would point out that i have a dead local store in timeStamp. Its seems that it doesnt like local variables! Thank you very much! Cheers

@amaembo
Copy link
Contributor

amaembo commented Dec 1, 2015

Hello! Which version of FindBugs are you using? How do you launch it (Eclipse plugin? IDEA plugin? Hudson? Jenkins? Maven? Ant? Manually?). If possible, please attach the minimal source file which produces false positive. Also please paste exact FindBugs warning report (if possible, an excerpt from findbugs XML file).

I cannot say for sure, but from your description it looks like you are looking on the old results. For example, you are using FindBugs in Eclipse IDE and did not switch on the automatic FindBugs launch on save, so it just shows you the message which was actual before you did some changes in the code.

@jcnoriega
Copy link
Author

Here is the info you requested:
Findbugs: 3.0.1
We launch it with gradle
The source file and the report excerpt are attached.
MyService.txt
ReportExcerpt.txt

@amaembo
Copy link
Contributor

amaembo commented Dec 19, 2015

I tried to reproduce it on my system, added missing classes see this gist:
https://gist.github.com/amaembo/34b32637ca05ff65eeb9

I see no findbugs reports (except the hardcoded filename) in this file. Can you reproduce it on your system with this file? If not, could you please provide a class file for your original code (ProfilePictureServiceImpl.class) which triggers the findbugs error? Thanks.

@ghost
Copy link

ghost commented Jul 27, 2016

@amaembo The official documentation for DLS_DEAD_LOCAL_STORE claims that "Sun's javac compiler often generates dead stores for final local variables. Because FindBugs is a bytecode-based tool, there is no easy way to eliminate these false positives."

Maybe the version/brand of javac compiler matters when trying to reproduce this problem?

(For the record, I cannot reproduce it with Oracle Java 1.8.0_101).

@iloveeclipse
Copy link
Member

This project continues development in a new home: https://github.com/spotbugs/spotbugs/

Please do not open new issues here anymore!

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

No branches or pull requests

3 participants