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

Inconsistency in SpotBugs Bug Description #1470

Closed
gloNelson opened this issue Mar 23, 2021 · 2 comments · Fixed by #1471
Closed

Inconsistency in SpotBugs Bug Description #1470

gloNelson opened this issue Mar 23, 2021 · 2 comments · Fixed by #1471

Comments

@gloNelson
Copy link
Contributor

gloNelson commented Mar 23, 2021

I found an inconsistency when reading the SpotBugs Bug Description.

All four bug patterns - DLS_DEAD_LOCAL_INCREMENT_IN_RETURN, DLS_OVERWRITTEN_INCREMENT, VO_VOLATILE_INCREMENT, and QF_QUESTIONABLE_FOR_LOOP are related to "increment" of a variable.

However, DLS_OVERWRITTEN_INCREMENT mentioned "increment/decrement", other three bug patterns just indicated "increment" without "decrement". So are in their examples of ++ not including --.

And I wrote tests for checking whether all of them support both increment and decrement.

//DLS_DEAD_LOCAL_INCREMENT_IN_RETURN for ++
int testDLS_DEAD_LOCAL_INCREMENT_IN_RETURN(){
  int i = 0;
  return i++; // Warning
}

//DLS_DEAD_LOCAL_INCREMENT_IN_RETURN for --
int testDLS_DEAD_LOCAL_INCREMENT_IN_RETURN1(){
  int i = 0;
  return i--; // Warning
}

//DLS_OVERWRITTEN_INCREMENT for ++
void testDLS_OVERWRITTEN_INCREMENT(){
  int i = 0;
  i = i++; // Warning
}

//DLS_OVERWRITTEN_INCREMENT for --
void testDLS_OVERWRITTEN_INCREMENT1(){
  int i = 0;
  i = i--; // Warning
}

//VO_VOLATILE_INCREMENT for ++
private volatile int x = 0;
void testVO_VOLATILE_INCREMENT() {
  try {
    x++; // Warning
  } finally {
  }
}

//VO_VOLATILE_INCREMENT for --
void testVO_VOLATILE_INCREMENT1() {
  try {
    x--; // Warning
  } finally {
  }
}


//QF_QUESTIONABLE_FOR_LOOP for ++
void testQF_QUESTIONABLE_FOR_LOOP(){
  int i = 0;
  for(int j = 0; j < 10; i++){ // Warning
    System.out.println("Hi");
    j++; 
  }
}

//QF_QUESTIONABLE_FOR_LOOP for --
void testQF_QUESTIONABLE_FOR_LOOP1(){
  int i = 0;
  for(int j = 0; j < 10; i--){ // Warning
    System.out.println("Hi");
    j--;
  }
}

As can be seen from results, both increment and decrement are supported in all four bug patterns mentioned above.

Therefore, it would be better to add decrement in their bug description so that it is not confusing when users reading.

@welcome
Copy link

welcome bot commented Mar 23, 2021

Thanks for opening your first issue here! 😃
Please check our contributing guideline. Especially when you report a problem, make sure you share a Minimal, Complete, and Verifiable example to reproduce it in this issue.

@gloNelson
Copy link
Contributor Author

I have created a pull request to fix this. Please help me review this. @KengoTODA Thanks a lot.

KengoTODA pushed a commit that referenced this issue Mar 25, 2021
* fix issue 1470

* requested changes of CHANGELOG.md
gamesh411 pushed a commit to gamesh411/spotbugs that referenced this issue Apr 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants