Thread: Bug in postgresql7.1 jdbc2 DatabaseMetaData class

Bug in postgresql7.1 jdbc2 DatabaseMetaData class

From
Robert Weiler
Date:
On line 1707 there is a dereference of 'relKind' which may very likely
be set to null. This can cause a null pointer exception. I've include
dthe workaround I am using, though there is almost certainly somethig
better.

Bob Weiler

String relKind;
    switch (r.getBytes(3)[0]) {
    case 'r':
        relKind = "TABLE";
        break;
    case 'i':
        relKind = "INDEX";
        break;
    case 'S':
        relKind = "SEQUENCE";
        break;
    default:
        relKind = null;
    }

    tuple[0] = null;        // Catalog name
    tuple[1] = null;        // Schema name
    tuple[2] = r.getBytes(1);    // Table name
    tuple[3] = relKind != null ? relKind.getBytes() : null;    // Table type
    tuple[4] = remarks;        // Remarks
    v.addElement(tuple);
      }

Re: Bug in postgresql7.1 jdbc2 DatabaseMetaData class

From
Bruce Momjian
Date:
I see your fix in the current sources so we should be OK:

    tuple[0] = null;        // Catalog name
    tuple[1] = null;        // Schema name
    tuple[2] = r.getBytes(1);   // Table name
    tuple[3] = (relKind==null) ? null : relKind.getBytes(); // Table type
    tuple[4] = remarks;     // Remarks
    v.addElement(tuple);

> On line 1707 there is a dereference of 'relKind' which may very likely
> be set to null. This can cause a null pointer exception. I've include
> dthe workaround I am using, though there is almost certainly somethig
> better.
>
> Bob Weiler
>
> String relKind;
>     switch (r.getBytes(3)[0]) {
>     case 'r':
>         relKind = "TABLE";
>         break;
>     case 'i':
>         relKind = "INDEX";
>         break;
>     case 'S':
>         relKind = "SEQUENCE";
>         break;
>     default:
>         relKind = null;
>     }
>
>     tuple[0] = null;        // Catalog name
>     tuple[1] = null;        // Schema name
>     tuple[2] = r.getBytes(1);    // Table name
>     tuple[3] = relKind != null ? relKind.getBytes() : null;    // Table type
>     tuple[4] = remarks;        // Remarks
>     v.addElement(tuple);
>       }
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026