If statement Becareful !!!

Becareful!!, this is what i encounter today, what a stupid “If statement” i created….ai..do you seen what error below?

if(this.putNode(estraierFts, ftsUrlSync));
{
	//delete record after update
	ftsUrlSyncBO.deleteFtsUrlSync(ftsUrlSync.getId());
}

Above statement compile successfully in Java, what i trying want to do is , when condition true, it will delete my records. However with above statement, it will delete my record no matter condition true or false. This is funny, did you notice what error above? …. haha notice carefully , “;” after a “If statement”..what a stupid mistake i made.. TT…. my eyes are blur…take a rest first

Correct statement should be following

if(this.putNode(estraierFts, ftsUrlSync))
{
	//delete record after update
	ftsUrlSyncBO.deleteFtsUrlSync(ftsUrlSync.getId());
}

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
5 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
6 Comment authors
Manoj SawantFaisalDasiamkyongShams Recent comment authors
newest oldest most voted
Manoj Sawant
Guest
Manoj Sawant

magic of Statement Terminator (;) in Java

Faisal
Guest
Faisal

Hehehe…U made me laugh mkyong. Thanks

Dasia
Guest
Dasia

That’s really thnkniig out of the box. Thanks!

Shams
Guest
Shams

thats why it will be a good idea for the opening brace in an if-block is placed next to the closing brace of the condition.
Code formatting really helps reduce bugs :D

ordersomabuyg
Guest
ordersomabuyg

Wow Cool !
Super Man
Nice Site