You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dan Payne <dp...@sotx.org> on 2002/08/22 18:21:17 UTC

Problem with return statement

All, getting this error:

com\payne\web\business\UnverifiedUserBO.java:30: missing return statement
        public UnverifiedUser createUnverifiedUser(UnverifiedUser uu) throws
Unv
erifiedUserException {

                     ^
1 error


Full code of the class com\payne\web\business\UnverifiedUserBO.java is
below.  The odd thing is that if I place the return statement outside of the
try { } catch { } finally { } then it works ok, however this doesn't seem
like good coding.  Any thoughts?  I've placed comments in the code where
there error is occurring as well as where it seems to work.

Thanks in advance ya'll.

-Dan

com\payne\web\business\UnverifiedUserBO.java
--------------------------------------------

package com.payne.web.business;

import com.payne.web.entity.Email;
import com.payne.web.entity.UnverifiedUser;
import com.payne.web.entity.UnverifiedUserTypeXref;

import com.payne.web.db.util.ConnectionPool;
import com.payne.web.db.util.LastInsertId;
import com.payne.web.db.UnverifiedUserDAO;
import com.payne.web.db.UnverifiedUserTypeXrefDAO;
import com.payne.web.db.CreateException;
import com.payne.web.db.FinderException;

import com.payne.web.util.AuthCodeGenerator;
import com.payne.web.util.Mailer;

import java.sql.SQLException;
import java.sql.Connection;

import java.util.Iterator;

public class UnverifiedUserBO {

	private ConnectionPool pool;

	public UnverifiedUserBO() {
		pool = ConnectionPool.getInstance();
	}

	public UnverifiedUser createUnverifiedUser(UnverifiedUser uu) throws
UnverifiedUserException {

		validateUnverifiedUser(uu);

		Connection con = null;
		boolean duplicate = false;

		try {

			con = pool.getConnection();

			uu.setRegistered();

			do {
				AuthCodeGenerator acg = new AuthCodeGenerator(con);
				uu.setAuthCode(acg.generate());
				duplicate = acg.checkDuplicate(uu.getAuthCode());
			} while (duplicate);

			UnverifiedUserDAO uuDAO = new UnverifiedUserDAO(con);
			uuDAO.create(uu);

			LastInsertId id = new LastInsertId(con);
			uu.setUnverifiedUserId(id.lastInsertId());

			for (int i = 0; i < uu.getUserTypeId().length; i++) {
				UnverifiedUserTypeXrefDAO uutxDAO = new UnverifiedUserTypeXrefDAO(con);
				uutxDAO.create(uu.getUnverifiedUserId(),uu.getUserTypeId()[i]);
			}

			Email email = new Email();
			email.setTo(uu.getEmail());
			email.setFrom("from@test.email");
			email.setSubject("Subject");
			email.setBody("Body" + email.getEmail());

			Mailer m = new Mailer();
			m.send(email);

			con.commit();

/* Problem Return Statement Next Line */
			return uu;

		} catch (Exception e) {
			try {
				if (con != null) {
					con.rollback();
					throw new UnverifiedUserException(e.getMessage());
				}
			} catch (SQLException sqle) {
				e.printStackTrace();
				throw new RuntimeException("error.unexpected");
			}
		} finally {
			try {
				if (con != null) { con.close(); }
			} catch (SQLException sqle) {
				sqle.printStackTrace();
				throw new RuntimeException("error.unexpected");
			}
		}

/* If return Statement Placed Here No Error Reported During Compilation */

	}

	public void deleteUnverifiedUser(int userId) throws UnverifiedUserException
{

		Connection con = null;

		try {

			con = pool.getConnection();

			UnverifiedUserDAO uuDAO = new UnverifiedUserDAO(con);
			uuDAO.remove(userId);

			con.commit();

		} catch (Exception e) {
			try {
				if (con != null) {
					con.rollback();
					throw new UnverifiedUserException(e.getMessage());
				}
			} catch (SQLException sqle) {
				e.printStackTrace();
				throw new RuntimeException("error.unexpected");
			}
		} finally {
			try {
				if (con != null) { con.close(); }
			} catch (SQLException sqle) {
				sqle.printStackTrace();
				throw new RuntimeException("error.unexpected");
			}
		}

	}

	public void validateUnverifiedUser(UnverifiedUser uu) throws
UnverifiedUserException {

		if (uu.getEmail().trim().equals("")) {
			throw new UnverifiedUserException("error.missing.email");
		}

		if (uu.getPassword().equals("")) {
			throw new UnverifiedUserException("error.missing.password");
		}

		if (uu.getPassword2().equals("")) {
			throw new UnverifiedUserException("error.missing.password2");
		}

		if (!uu.getPassword().equals(uu.getPassword2())) {
			throw new UnverifiedUserException("error.match.passwords");
		}

		if (uu.getFname().trim().equals("")) {
			throw new UnverifiedUserException("error.missing.fname");
		}

		if (uu.getLname().trim().equals("")) {
			throw new UnverifiedUserException("error.missing.lname");
		}

		if (uu.getLocationId() == 0) {
			throw new UnverifiedUserException("error.missing.locationId");
		}

		if (uu.getUserTypeId().length == 0) {
			throw new UnverifiedUserException("error.missing.userTypeId");
		}

		if (uu.getEmailTypeId() == 0) {
			throw new UnverifiedUserException("error.missing.emailTypeId");
		}

	}

}


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>