Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.lang.VerifyError - Incompatible object argument for function call

658307Jul 10 2008 — edited Jul 17 2008
Hi all,

I'm developing a JSP application (powered by Tomcat 4.0.1 in JDK 1.3, in Eclipse 3.3). Among other stuff I have 3 classes interacting with an Oracle database, covering 3 use cases - renaming, adding and deleting an database object. The renaming class simply updates the database with a String variable it receives from the request object, whereas the other two classes perform some calculations with the request data and update the database accordingly.
When the adding or deleting classes are executed, by performing the appropriate actions through the web application, Tomcat throws the following:
java.lang.VerifyError: (class: action/GliederungNewAction, method: insertNewNode signature: (Loracle/jdbc/driver/OracleConnection;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V) Incompatible object argument for function call
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:120)
	at action.ActionMapping.perform(ActionMapping.java:53)
	at ControllerServlet.doResponse(ControllerServlet.java:92)
	at ControllerServlet.doPost(ControllerServlet.java:50)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
...
The renaming works fine though. I have checked mailing lists and forums as well as contacted the company's java support but everything I have tried out so far, from exchanging the xerces.jar files found in JDOM and Tomcat to rebuidling the project didn't help.
I just can't explain to myself why this error occurs and I don't see how some additional Java code in the other 2 classes could cause it?

I realize that the Tomcat and JDK versions I'm using are totally out of date, but that's company's current standard and I can't really change that.

Here's the source code. I moved parts of the business logic from Java to Oracle recently but I left the SQL statements that the Oracle stored procedures are executing if it helps someone.
package action;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.StringTokenizer;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import oracle.jdbc.driver.OracleConnection;

/**
 * This class enables the creation and insertion of a new catalogue node. A new node
 * is always inserted as the last child of the selected parent node.
 *
 */
public class GliederungNewAction implements Action {
	
	
	
	public String perform(ActionMapping mapping, HttpServletRequest request,
			HttpServletResponse response) {
		
		// fetch the necessary parameters from the JSP site
		// the parent attribute is the selected attribute!
		String parent_attribute = request.getParameter("attr");
		String catalogue = request.getParameter("catalogue");
		int parent_sequenceNr = Integer.parseInt(request.getParameter("sort_sequence"));
		
		// connect to database     
		HttpSession session = request.getSession();    
		db.SessionConnection sessConn = (db.SessionConnection) session.getAttribute("connection");
		if (sessConn != null) {
			try {
				sessConn.setAutoCommit(false);
				OracleConnection connection = (OracleConnection)sessConn.getConnection();
				
				int lastPosition = getLastNodePosition( getLastChildAttribute(connection, catalogue, parent_attribute) );
				String newNodeAttribute = createNewNodeAttribute(parent_attribute, lastPosition);
				
				// calculate the sequence number
				int precedingSequenceNumber = getPrecedingSequenceNumber(connection, catalogue, parent_attribute);
				if ( precedingSequenceNumber == -1 ) {
					precedingSequenceNumber = parent_sequenceNr;
				}
				int sortSequence = precedingSequenceNumber + 1;
				setSequenceNumbers(connection, catalogue, sortSequence);
				
				// insert the new node into DB
				insertNewNode(connection, catalogue, newNodeAttribute, parent_attribute, "Neuer Punkt", sortSequence);
				
				connection.commit();
				
			} catch(SQLException ex) {
				ex.printStackTrace();
			}

		}

		return mapping.getForward();
	}
	
	/**
	 * Creates, fills and executes a prepared statement to insert a new entry into the specified table, representing
	 * a new node in the catalogue.
	 */
	private void insertNewNode(OracleConnection connection, String catalogue, String attribute, String parent_attribute, String description, int sortSequence) {
		
		try {
			String callAddNode = "{ call fasi_lob.pack_gliederung.addNode(:1, :2, :3, :4, :5) }";
			CallableStatement cst;
			cst = connection.prepareCall(callAddNode);
			cst.setString(1, catalogue);
			cst.setString(2, attribute);
			cst.setString(3, parent_attribute);
			cst.setString(4, description);
			cst.setInt(5, sortSequence);
			
			cst.execute();
			cst.close();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		
		
//		String insertNewNode = "INSERT INTO vstd_media_cat_attributes " +
//				"(catalogue, attribute, parent_attr, description, sort_sequence) VALUES(:1, :2, :3, :4, :5)";
//		PreparedStatement insertStmt;
//		try {
//			insertStmt = connection.prepareStatement(insertNewNode);
//			insertStmt.setString(1, catalogue);
//			insertStmt.setString(2, attribute);
//			insertStmt.setString(3, parent_attribute);
//			insertStmt.setString(4, description);
//			insertStmt.setInt(5, sortSequence);
//			
//			insertStmt.execute();
//			insertStmt.close();
//		} catch (SQLException e) {
//			e.printStackTrace();
//		}
		
	}
	
	/**
	 * This method returns the attribute value of the last child of the parent under which
	 * we want to insert a new node. The result set is sorted in descending order and only the
	 * first result (that is, the last child under this parent) is fetched.
	 * If the parent node has no children, "parent_attr.0" is returned.  
	 * @param connection
	 * @param catalogue
	 * @param parent_attribute
	 * @return attribute of the last child under this parent, or "parent_attr.0" if parent has no children
	 */
	private String getLastChildAttribute(OracleConnection connection, String catalogue, String parent_attribute) {
		String queryLastChild = "SELECT attribute FROM vstd_media_cat_attributes " +
								"WHERE catalogue=:1 AND parent_attr=:2 ORDER BY sort_sequence DESC";
		
		String lastChildAttribute;
		PreparedStatement ps;
		try {
			ps = connection.prepareStatement(queryLastChild);
			ps.setString(1, catalogue);
			ps.setString(2, parent_attribute);
			
			ResultSet rs = ps.executeQuery();
			/* If a result is returned, the selected parent already has children.
			 * If not set the lastChildAttribute to parent_attr.0
			 */
			if (rs.next()) {
				lastChildAttribute = rs.getString("attribute");
			} else {
				lastChildAttribute = parent_attribute.concat(".0");
			}
			rs.close();
			return lastChildAttribute;
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
		
	}
	
	/**
	 * This helper method determines the position of the last node in the attribute.
	 * i.e for 3.5.2 it returns 2, for 2.1 it returns 1 etc. 
	 * @param attribute
	 * @return position of last node in this attribute
	 */
	private int getLastNodePosition(String attribute) {
		
		StringTokenizer tokenizer = new StringTokenizer(attribute, ".");
		String lastNodePosition = "0";
		
		while( tokenizer.hasMoreTokens() ) {
			lastNodePosition = tokenizer.nextToken();
		}
		return Integer.parseInt(lastNodePosition);
		
	}
	
	/**
	 * This method calculates the attribute of a node being inserted
	 * by incrementing the last child position by 1 and attaching the
	 * incremented position to the parent.
	 * @param parent_attr
	 * @param lastPosition
	 * @return attribute of the new node
	 */
	private String createNewNodeAttribute(String parent_attr, int lastPosition) {
		String newPosition = new Integer(lastPosition + 1).toString();
		return parent_attr.concat("." + newPosition);
		
	}
	
	/**
	 * This method checks if the required sequence number for a new node is already in use and
	 * handles the sequence numbers accordingly.
	 * If the sequence number for a new node is NOT IN USE, the method doesn't do anything.
	 * If the sequence number for a new node is IN USE, the method searches for the next free
	 * sequence number by incrementing the number by one and repeating the query until no result
	 * is found. Then all the sequence numbers between the required number (including, >= relation) 
	 * and the nearest found free number (not including, < relation) are incremented by 1, as to
	 * make space for the new node. 
	 * @param connection
	 * @param catalogue
	 * @param newNodeSequenceNumber required sequence number for the new node
	 */
	private void setSequenceNumbers(OracleConnection connection, String catalogue, int newNodeSequenceNumber) {
		
		// 1. check if the new sequence number exists - if no do nothing
		// if yes - increment by one and see if exists
		// 		repeat until free sequence number exists
		// when found increment all sequence numbers freeSeqNr > seqNr >= newSeqNr
		
		String query = "SELECT sort_sequence FROM vstd_media_cat_attributes " +
				"WHERE catalogue=:1 AND sort_sequence=:2";
		
		PreparedStatement ps;
		try {
			ps = connection.prepareStatement(query);
			ps.setString(1, catalogue);
			ps.setInt(2, newNodeSequenceNumber);			
			
			ResultSet rs = ps.executeQuery();
			
			// if no result, the required sequence number is free - nothing to do
			if( rs.next() ) {
				int freeSequenceNumber = newNodeSequenceNumber;
				
				do {
					ps.setString(1, catalogue);
					ps.setInt(2, freeSequenceNumber++);
					rs = ps.executeQuery();
					
				} while( rs.next() );
				
				// increment sequence numbers - call stored procedure
				String callUpdateSeqeunceNrs = "{ call fasi_lob.pack_gliederung.updateSeqNumbers(:1, :2, :3) }";
				CallableStatement cst = connection.prepareCall(callUpdateSeqeunceNrs);
				cst.setString(1, catalogue);
				cst.setInt(2, newNodeSequenceNumber);
				cst.setInt(3, freeSequenceNumber);
				cst.execute();
				cst.close();
				
				
//				String query2 = "UPDATE vstd_media_cat_attributes " +
//							   "SET sort_sequence = (sort_sequence + 1 ) " +
//							   "WHERE catalogue=:1 sort_sequnce >=:2 AND sort_sequence <:3";
//				
//				PreparedStatement ps2;
//				ps2 = connection.prepareStatement(query2);
//				ps2.setString(1, catalogue);
//				ps2.setInt(2, newNodeSequenceNumber);
//				ps2.setInt(3, freeSequenceNumber);
//				ps.executeUpdate();
//				ps.close();
			
			} // end of if block
			rs.close();
			
		} catch (SQLException e) {
			e.printStackTrace();
			
		}
	
	}
	
	/**
	 * This method finds the last sequence number preceding the sequence number of a node
	 * that is going to be inserted. The preceding sequence number is required to calculate
	 * the sequence number of the new node.
	 * We perform a hierarchical query starting from the parent node: if a result is returned,
	 * we assign the parent's farthest descendant's node sequence number; if no result
	 * is returned, we assign the parent's sequence number. 
	 *      
	 * @param connection
	 * @param catalogue
	 * @param parent_attr parent attribute of the new node
	 * @return
	 */
	private int getPrecedingSequenceNumber(OracleConnection connection, String catalogue, String parent_attr) {
		
		int sequenceNumber = 0;
		
		String query = "SELECT sort_sequence FROM vstd_media_cat_attributes " +
					   "WHERE catalogue=:1 " +
					   "CONNECT BY PRIOR attribute = parent_attr START WITH parent_attr=:2 " +
					   "ORDER BY sort_sequence DESC";
		
		try {
			PreparedStatement ps = connection.prepareStatement(query);
			ps.setString(1, catalogue);
			ps.setString(2, parent_attr);
			
			ResultSet rs = ps.executeQuery();
			if ( rs.next() ) {
				sequenceNumber = rs.getInt("sort_sequence");
			} else {
				// TODO: ggf fetch from request!
				sequenceNumber = -1;
			}
			rs.close();
			ps.close();
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		return sequenceNumber;
		
		
	}
	
	
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 14 2008
Added on Jul 10 2008
1 comment
600 views