Bug 37582 - Simple PUT document request results in exception on Oracle 9i
Summary: Simple PUT document request results in exception on Oracle 9i
Status: NEW
Alias: None
Product: Slide
Classification: Unclassified
Component: Stores (show other bugs)
Version: 2.1
Hardware: Other Linux
: P1 major (vote)
Target Milestone: ---
Assignee: Slide Developer List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-21 22:08 UTC by Christopher Fitch
Modified: 2005-11-21 13:08 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christopher Fitch 2005-11-21 22:08:40 UTC
Environment Details:
Linux 2.6 kernel(Suse 9.1)
JDK 1.4.2_06
Oracle 9.2 DB and JDBC Driver

Description:
Upon executing a PUT document request, I receive the following exception(with
relevant trace):

java.lang.IllegalArgumentException: object is not an instance of declaring class
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at
org.apache.slide.store.impl.rdbms.OracleRDBMSAdapter.storeContent(OracleRDBMSAdapter.java:142)


Digging around the problem results from an incorrect usage of java reflection to
execute a method.

Specifically:

In stores section, the class
org.apache.slide.store.impl.rdbms.OracleRDBMSAdapter declares the following
instance variable: 

    protected Method blobGetOutStreamMethod;


The constructor for the class is as follows:

    public OracleRDBMSAdapter(Service service, Logger logger) 
        throws ClassNotFoundException, NoSuchMethodException 
    {
        super(service, logger);
        
        Class bCls = Class.forName("oracle.sql.BLOB");
        blobGetOutStreamMethod = bCls.getMethod("getBinaryOutputStream", new
Class[] {});
    }

Later on, the Adapter attempts to retrieve the java.io.OutputStream for the Blob
by making this call:

    os = (OutputStream) blobGetOutStreamMethod.invoke(bObj, new Object[] {});


Though syntactically correct, this code results in the above exception.

In the constructor, the method is retrieved from a Class object and NOT an
instance of the Class itself.

According to the javadoc for the Method.invoke() call, invoke() will throw:

IllegalArgumentException - if the method is an instance method and the specified
object argument is not an instance of the class or interface declaring the
underlying method 

Since the method was retrieved from a Class object and not an instance, it's not
an Instance method. This is discussed on the Sun Java forums.

The correct code is as follows:

replace this line(line 142) 

    os = (OutputStream) blobGetOutStreamMethod.invoke(bObj, new Object[] {});

with the following two lines:

    Method blobGetOutputStreamMethod =
bObj.getClass().getMethod("getBinaryOutputStream",new Class[0]);
    os = (OutputStream) blobGetOutputStreamMethod.invoke(bObj, new Object[0]);

and remove the two lines in the constructor.

Thanks!