• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How would I rewrite this to satisfy the code checker?

 
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm using Java 1.5, Eclipse Galileo on Mac 10.5.6 and the code checking plug-in (PMD) is complaining about the below code ...



Unfortunately, I'm getting the PMD warning, "Avoid empty while statements". Anyone know how to rewrite the above to satisfy the code checker?

Thanks, - Dave
 
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dave:

Change line 3 to read:

John.
 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks but where you put "// your code here ", there's no actual code to put there. If I write it the way you suggest, the code checker still complains about an empty while statement.

- Dave
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The semicolon after while ( . . . ) is almost always an error.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you using an empty statement after the while in the first place? You appear to be reading something, then not doing anything with it.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe that's the point, to simply clear all data from the stream. In this case, it most certainly is; the purpose is to calculate the SHA-1 digest.

I think what John meant is put a simple comment in the while loop that immediately explains exactly why you are doing nothing:
This always gets rid of the empty block warnings Eclipse is giving me, and it also tells anyone reading your code why the block is empty.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, rob. I hadn't realised that.
 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I understood that John meant to only place a comment in the while loop, but what I was saying is when I tried that, PMD, the code checker that is a plug-in for Eclipse, complained with the warning, "Avoid empty while statements", so even with the braces and the comment, it still considers the while statement empty.

So, the question remains, is there any way to rewrite that to achieve the same thing but satisfy the code checker?

Thanks for all your ideas, - Dave
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dave:

You can put in a NOPMD directive to have PMD ignore that instance:

The //NOPMD directive has to be on the same line as the one you're getting the warning on.

John.
 
Have you no shame? Have you no decency? Have you no tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic