Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unreachable code question

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the following code, where BOLDED, I do not understand why this is UNREACHABLE CODE:

public class EndTransactionSOAPImpl implements org.tempuri.EndTransaction_PortType{
public org.texashealth.www.SCM.DataTier.GenericResponse.GenericResponse
endTransaction(org.texashealth.www.SCM.DataTier.ETRequest.EndTransactionRequest endTransaction
) throws java.rmi.RemoteException {

// Create the "GenericResponse" and "Header" objects.
GenericResponse response = new GenericResponse();
Header responseheader = new Header();

// Stuff the responseheader with the hardcoded VERSION and STATUS.
responseheader.setVersion(BigInteger.valueOf(1));
responseheader.setStatus(Status.fromString("OK"));

// Stuff the "response" object variable by passing
// in the header object.
response.setHeader(responseheader);

// Delete or keep the transaction by verifying the transaction exists in the hash table.
Transaction transaction = new Transaction();
if (endTransaction.getHeader().getVersion().intValue() != 1)
responseheader.setStatus(Status.fromString("VersionNotSupported"));
return response;

int transID = endTransaction.getTransactionID().intValue();
if (Transaction.get(transID) == null)
responseheader.setStatus(Status.fromString("InvalidTransactionID"));
return response;

Transaction.remove(endTransaction.getTransactionID().intValue());
responseheader.setStatus(Status.fromString("OK"));
return response;
}
}

Any help or direction would be appreciated.

Thanks.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

That's what's stopping you. Its always a good idea to use curly brackets {} to demarcate blocks of logic, such as if conditions. Without the brackets, your if() only includes the one line after it in its conditional block.
[ July 08, 2005: Message edited by: Paul Sturrock ]
 
Shrinivas Mujumdar
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
See the line above bold variable you are saying return statement so how you can expect the control will go to the next line. The if statement you have written must have a {}block after that & return should be inside that block.

Shrinivas
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The braces {} were indeed missing. Stupid mistake, sorry about that.

Thanks for the responses. Sure appreciate the time.

Regards.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic