php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9162 Java support corrupts Hashtables
Submitted: 2001-02-07 15:28 UTC Modified: 2002-03-25 00:00 UTC
From: freifeld at turbogenomics dot com Assigned:
Status: No Feedback Package: Java related
PHP Version: 4.0.4pl1 OS: Linux, RH6.2
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2001-02-07 15:28 UTC] freifeld at turbogenomics dot com
This bug is with the Java support in PHP4. PHP seems to try to treat Java Hashtable objects as PHP-native arrays, with several negative impacts. First of all, Java Hashtables have no internal concept of ordering or null termination, nor do they have an internal "current" pointer. Therefore, if you try to travserse a Java Hashtable as you would a PHP array, you will run off the end! However, since the Hashtable is not an object (under PHP), you cannot call $my_hash->get( "x" ) or $my_hash->put( "y" ).

Second of all, if you try to pass such a Hashtable BACK to a Java class method, you will find that the Hashtable has been corrupted, and all your datatypes changed and you will get various NullPointerExceptions or illegal cast exceptions.

It seems to me the most natural approach at this point would be to just treat Java Hashtables as generic objects, and therefore retain the get() and put() methods. That way you don't corrupt the Hashtable, and you don't let anyone go off the end of any arrays.

I don't know if this kind of thing happens with other Java object classes.

There is a workaround whereby one can, in Java, explicitly repair a corrupted Hashtable, but that is pretty ugly. If you are interested in looking at the workaround, email me.

Here is a code snippet illustrating what I mean:

MyClass.java:

public class MyClass {

    public MyClass() { }

    public Hashtable makeHash( int ikey, int ival, String skey, String sval ) {
        Hashtable myhash = new Hashtable();
        myhash.put( ikey, ival );
        myhash.put( skey, sval );
        myhash.put( "myname", "joe" );
        return myhash;
    }

    public String getSomething( Hashtable myhash ) {
        return myhash.get( "myname" );
    }
}

MyPage.php

<?

$my_java = new Java( "MyClass" );
$my_hash = my_java->makeHash( 1,2,"yourname", "steve" );

// watch this:

print( implode( ",", $my_hash ) );   // explosion! off the end of the array

// or, 

print( $my_java->getSomething() );  // java exception!

?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-08 10:58 UTC] freifeld at turbogenomics dot com
Just in case you were confused, the java method getSomething() should return (String) myhash.get( "myname" ), and the PHP call should be my_java->getSomething( $my_hash ). You get the idea.
 [2002-02-24 06:04 UTC] yohgaki@php.net
Please test with  PHP 4.1.1+JDK 1.2 and report back Thanks.
 [2002-03-25 00:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Nov 24 10:01:23 2020 UTC