Skip to content

A MappedUDT isn't prevented from mirroring a NUL-terminated (typlen -2) type #370

Closed

Description

@jcflack

The ability for a MappedUDT to mirror scalar types, not only composite types, appeared fifteen years ago in c525927, along with the apparently definitive comment,

A scalar mapping that is implemented in Java will have ... parse ... and ... toString .... A pure mapping (i.e. no Java I/O methods) will not ....

Indeed, whenever a UDT was first encountered in function resolution, it would be registered with isJavaBasedScalar true, whereas one first encountered in type resolution, because it appears in the type map, would be registered with isJavaBasedScalar false, and would have its parse and toString slots unconditionally nulled.

However, that comment and logic can't be squared with even older logic going back to e0222e3 where _UDT_coerceDatum and _UDT_coerceObject will use the parse and toString slots, not the readSQL and writeSQL slots, if the type has PostgreSQL's NUL-terminated internal form (indicated by typlen of -2).

The builtin PostgreSQL type cstring is such a type. By mapping a PL/Java type to cstring and attempting to use it:

SELECT sqlj.add_type_mapping(
  'pg_catalog.cstring',
  'org.postgresql.pljava.example.annotation.Point');

SELECT * FROM
  (SELECT 'blah'::cstring) AS p,
  javatest.roundtrip(p) AS (typepg text);

... all these years later, one can get a java.lang.NullPointerException: Cannot read field "acc" because "target" is null in PL/Java 1.6.2, or a backend segfault in 1.5.8.

The failure has nothing to do with blah\0 being invalid as a Point representation. It never gets that far. :)

Activity

  1. jcflack commented on Oct 10, 2021

    @jcflack
    ContributorAuthor

    Believed resolved in 1.6.3. Should probably be backported to 1.5.

  2. added a commit that references this issue on Jan 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions