[ 
https://issues.apache.org/jira/browse/PHOENIX-1376?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14185105#comment-14185105
 ] 

Sergio Lob commented on PHOENIX-1376:
-------------------------------------

While the java 6 api documentation states that it does not require the address 
of the object to be returned, it does suggest that this is the typical 
implementation, as per the following:

The java 6 api documentation for Object.toString states that:

Object.toString
public String toString()
Returns a string representation of the object. In general, the toString method 
returns a string that "textually represents" this object. The result should be 
a concise but informative representation that is easy for a person to read. It 
is recommended that all subclasses override this method. 
The toString method for class Object returns a string consisting of the name of 
the class of which the object is an instance, the at-sign character `@', and 
the unsigned hexadecimal representation of the hash code of the object. In 
other words, this method returns a string equal to the value of: 

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 
Returns:a string representation of the object.

 ===============
The java 6 api documentation for Object.hashCode states:

Object.hashCode
public int hashCode()
Returns a hash code value for the object. This method is supported for the 
benefit of hashtables such as those provided by java.util.Hashtable. 
The general contract of hashCode is: 
•Whenever it is invoked on the same object more than once during an execution 
of a Java application, the hashCode method must consistently return the same 
integer, provided no information used in equals comparisons on the object is 
modified. This integer need not remain consistent from one execution of an 
application to another execution of the same application. 
•If two objects are equal according to the equals(Object) method, then calling 
the hashCode method on each of the two objects must produce the same integer 
result. 
•It is not required that if two objects are unequal according to the 
equals(java.lang.Object) method, then calling the hashCode method on each of 
the two objects must produce distinct integer results. However, the programmer 
should be aware that producing distinct integer results for unequal objects may 
improve the performance of hashtables. 

As much as is reasonably practical, the hashCode method defined by class Object 
does return distinct integers for distinct objects. (This is typically 
implemented by converting the internal address of the object into an integer, 
but this implementation technique is not required by the JavaTM programming 
language.) 

Returns:a hash code value for this object.


> java.lang.NullPointerException occurs in JDBC driver
> ----------------------------------------------------
>
>                 Key: PHOENIX-1376
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-1376
>             Project: Phoenix
>          Issue Type: Bug
>    Affects Versions: 4.1
>         Environment: windows 7
>            Reporter: Sergio Lob
>
> When our software attempts to print out a valid resultSet object via 
> System.out.println(), a java.lang.NullPointerException is generated within 
> the Phoenix JDBC driver. I would expect that performing toString() on an 
> object should not cause a problem. My experience is that normally the address 
> of the object (among other things) is usually returned.  This in effect 
> causes the diagnostic mode of our software to be un-usable, which makes this 
> a major issue for us.  
> Here is the program log showing the exception and the java program:
> ======================================================
> program log:
> =========
> log4j:WARN No appenders could be found for logger 
> (org.apache.hadoop.conf.Configuration.deprecation).
> log4j:WARN Please initialize the log4j system properly.
> log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more 
> info.
> Connected to jdbc:phoenix:cdh5hive:2181
> Driver       org.apache.phoenix.jdbc.PhoenixDriver
> Version      4.1
> Preparing statement
> Executing prepared statement
> call rs=stmt.executeQuery(), stmt =SELECT * FROM SERGIO
> java.lang.NullPointerException
>       at 
> org.apache.phoenix.schema.tuple.ResultTuple.toString(ResultTuple.java:68)
>       at java.lang.String.valueOf(Unknown Source)
>       at java.lang.StringBuilder.append(Unknown Source)
>       at 
> org.apache.phoenix.jdbc.PhoenixResultSet.toString(PhoenixResultSet.java:1236)
>       at java.lang.String.valueOf(Unknown Source)
>       at java.lang.StringBuilder.append(Unknown Source)
>       at SimpleSelect.main(SimpleSelect.java:60)
> ========================================================
> The program follows:
> ================
> import java.net.URL;
> import java.sql.*;
> class SimpleSelect {
> public static void main (String args[]) {
>     String url = "jdbc:phoenix:cdh5hive:2181";
>       String query = "SELECT * FROM SERGIO"; 
>       try {
>               // Load the phoenix driver
>           Class.forName ("org.apache.phoenix.jdbc.PhoenixDriver");
> //          DriverManager.setLogStream(System.out);
>               // Attempt to connect to a driver.  Each one
>               // of the registered drivers will be loaded until
>               // one is found that can process this URL
>               Connection con = DriverManager.getConnection (
>                       url, null, null);
>               // If we were unable to connect, an exception
>               // would have been thrown.  So, if we get here,
>               // we are successfully connected to the URL
>               // Check for, and display and warnings generated
>               // by the connect.
>               checkForWarning (con.getWarnings ());
>               // Get the DatabaseMetaData object and display
>               // some information about the connection
>               DatabaseMetaData dma = con.getMetaData ();
>               System.out.println("\nConnected to " + dma.getURL());
>               System.out.println("Driver       " + 
>                       dma.getDriverName());
>               System.out.println("Version      " +
>                       dma.getDriverVersion());
>               System.out.println("");
>               // Create a Statement object so we can submit
>               // SQL statements to the driver
>               System.out.println("Preparing statement");
>               PreparedStatement stmt = con.prepareStatement (query);
>               // Submit a query, creating a ResultSet object
>               System.out.println("Executing prepared statement");
>         System.out.println("call rs=stmt.executeQuery(), stmt ="+stmt);
>               ResultSet rs = stmt.executeQuery();
>         // The following line causes NullPointerException
>         System.out.println("return rs=stmt.executeQuery(), rs ="+rs);
>               // Display all columns and rows from the result set
>               System.out.println("Displaying result set");
>               dispResultSet (rs);
>               // Close the result set
>               rs.close();
>               // Close the statement
>               stmt.close();
>               // Close the connection
>               con.close();
>       }
>       catch (SQLException ex) {
>               // A SQLException was generated.  Catch it and
>               // display the error information.  Note that there
>               // could be multiple error objects chained
>               // together
>       System.out.println ("\n*** SQLException caught ***\n");
>       while (ex != null) {
>               System.out.println ("SQLState: " +
>                               ex.getSQLState ());
>               System.out.println ("Message:  " + ex.getMessage ());
>               System.out.println ("Vendor:   " +
>                               ex.getErrorCode ());
>               ex = ex.getNextException ();
>               System.out.println ("");
>               }
>       }
>       catch (java.lang.Exception ex) {
>               // Got some other type of exception.  Dump it.
>               ex.printStackTrace ();
>       }
> }
> //-------------------------------------------------------------------
> // checkForWarning
> // Checks for and displays warnings.  Returns true if a warning
> // existed
> //-------------------------------------------------------------------
> private static boolean checkForWarning (SQLWarning warn)      
>               throws SQLException  {
>       boolean rc = false;
>       // If a SQLWarning object was given, display the
>       // warning messages.  Note that there could be
>       // multiple warnings chained together
>       if (warn != null) {
>               System.out.println ("\n *** Warning ***\n");
>               rc = true;
>               while (warn != null) {
>                       System.out.println ("SQLState: " +
>                               warn.getSQLState ());
>                       System.out.println ("Message:  " +
>                               warn.getMessage ());
>                       System.out.println ("Vendor:   " +
>                               warn.getErrorCode ());
>                       System.out.println ("");
>                       warn = warn.getNextWarning ();
>               }
>       }
>       return rc;
> }
> //-------------------------------------------------------------------
> // dispResultSet
> // Displays all columns and rows in the given result set
> //-------------------------------------------------------------------
> private static void dispResultSet (ResultSet rs)
>       throws SQLException
> {
>       int i;
>       // Get the ResultSetMetaData.  This will be used for
>       // the column headings
>       ResultSetMetaData rsmd = rs.getMetaData ();
>       // Get the number of columns in the result set
>       int numCols = rsmd.getColumnCount ();
>       // Display column headings
>       for (i=1; i<=numCols; i++) {
>               if (i > 1) System.out.print(",");
>               System.out.print(rsmd.getColumnLabel(i));
>       }
>       System.out.println("");
>       
>       // Display data, fetching until end of the result set
>       boolean more = rs.next ();
>       while (more) {
>               // Loop through each column, getting the
>               // column data and displaying
>               for (i=1; i<=numCols; i++) {
>                       if (i > 1) System.out.print(",");
>                       System.out.print(rs.getString(i));
>               }
>               System.out.println("");
>               // Fetch the next result set row
>               more = rs.next ();
>       }
> }
> }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to