Ticket #2943 (closed defect: invalid)

Opened 4 years ago

Last modified 4 years ago

Bug and fix: GDAL java bandings

Reported by: xxcool Owned by: rouault
Priority: normal Milestone:
Component: JavaBindings Version: 1.6.0
Severity: normal Keywords:
Cc: warmerdam

Description

when try to test gdal java bandings with GDALtest , 3 bugs appear: ERROR 10: Pointer 'hObject' is NULL in 'GDALGetDescription'. ERROR 10: Pointer 'hObject' is NULL in 'GDALGetDescription'. ERROR 10: Pointer 'hObject' is NULL in 'GDALGetMetadata'.

I fixed them by change the decoration of swigCPtr in the MajorObject? to protected, and delete the declaration of swigCPtr in the Dataset. Hope it's useful to the guy who meet this problem.

Change History

Changed 4 years ago by warmerdam

  • cc warmerdam added
  • owner changed from aaime to rouault

Changed 4 years ago by rouault

xxcool,

you indicate that the version of GDAL you use is GDAL 1.6.0, but GDALtest doesn't even compile for that version, so I don't really understand how you could have hit those bugs.

If you're interested in using the Java bindings, I'd encourage you to test the current development version of GDAL where I have done major changes to improve the Java bindings. Fixing bugs in the Java bindings in maintenance versions of previously released version of GDAL would be impratical, but I'd happy to get feedback on how they behave for the future GDAL 1.7.0. You can grab a nightly snapshot for that purpose (see gdal-svntrunk on  http://download.osgeo.org/gdal/daily/).

I've reviewed the Java generate code but don't understand why the changes in MajorObject? should be necessary. Your change is probably unharmful in GDAL context (but it would be incorrect if the swig mapping were done on C++ objects with multiple inheritance...), but I don't understand why it actually fixes something. And I don't get the errors you report with the current development version...

So all in all, you'd need to give me more details on the exact version GDAL you're using, exact patches you could have applied, precise way of reproducing your issue, and rationale for your changes on swigCPtr.

Changed 4 years ago by xxcool

the version i am using is 1.6.0 Latest Stable Release - December 2008, i got it here:  http://download.osgeo.org/gdal/gdal-1.6.0.tar.gz there indeed is a GDALtest.java in gdal-1.6.0/swig/java/apps, the changes i made are in the MajorObject?.java and Dataset.java file. the bug is only exists in javabings, i modified it just according to the error report in eclipse, it seems that super(gdalJNI.SWIGDatasetUpcast(cPtr), cMemoryOwn) in the Dataset's constructor doesn't pass the cPtr to MajorObject? correctly. in order to get it work, i made those changes.

Changed 4 years ago by rouault

I'm afraid we're not talking about the same GDAL...

GDALtest.java from gdal-1.6.0 can't compile without applying the following changes in swig/include/gdal.i and in swig/include/java/gdal_java.i :

Index: ../include/java/gdal_java.i
===================================================================
--- ../include/java/gdal_java.i	(révision 16749)
+++ ../include/java/gdal_java.i	(copie de travail)
@@ -63,13 +63,13 @@
 }
 } /* extend */
 
-%typemap(javaimports) GDALColorTable %{
+%typemap(javaimports) GDALColorTableShadow %{
 /* imports for getIndexColorModel */
 import java.awt.image.IndexColorModel;
 import java.awt.Color;
 %}
 
-%typemap(javacode) GDALColorTable %{
+%typemap(javacode) GDALColorTableShadow %{
 /* convienance method */
   public IndexColorModel getIndexColorModel(int bits) {
     int size = GetCount();
Index: ../include/gdal.i
===================================================================
--- ../include/gdal.i	(révision 16749)
+++ ../include/gdal.i	(copie de travail)
@@ -444,9 +444,7 @@
 // Define the ColorTable object.
 //
 //************************************************************************
-#if !defined(SWIGJAVA)
 %include "ColorTable.i"
-#endif
 
 //************************************************************************
 //

Otherwise you'll get those errors :

apps/GDALtest.java:214: cannot find symbol
symbol  : method GetCount()
location: class org.gdal.gdal.SWIGTYPE_p_GDALColorTableShadow
						+ poBand.GetRasterColorTable().GetCount() + " entries.");
						                              ^
apps/GDALtest.java:215: cannot find symbol
symbol  : method GetCount()
location: class org.gdal.gdal.SWIGTYPE_p_GDALColorTableShadow
				for(int i = 0; i < poBand.GetRasterColorTable().GetCount(); i++) {
				                                               ^
apps/GDALtest.java:217: cannot find symbol
symbol  : method GetColorEntry(int)
location: class org.gdal.gdal.SWIGTYPE_p_GDALColorTableShadow
							poBand.GetRasterColorTable().GetColorEntry(i));
							                            ^
apps/GDALtest.java:293: cannot find symbol
symbol  : method getIndexColorModel(int)
location: class org.gdal.gdal.SWIGTYPE_p_GDALColorTableShadow
			cm = poBand.GetRasterColorTable().getIndexColorModel(
			                                 ^
Note: apps/GDALtest.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
4 errors

So either you've made the above changes, either you've commented out code about ColorTable? in GDALtest.java...

And what errors did exactly Eclipse report about the Dataset's constructor ?

For the moment, I don't see what I can do with your ticket...

Changed 4 years ago by xxcool

sorry, there is no error reported about the Dataset's constructor, i infered that according to the report of the 3 errors. ERROR 10: Pointer 'hObject' is NULL in 'GDALGetDescription'.

ERROR 10: Pointer 'hObject' is NULL in 'GDALGetMetadata'.

ERROR 10: Pointer 'hObject' is NULL in 'GDALGetMetadata'.

And i do commented out the colortable in GDALtest.java, are the errors related with this?

Changed 4 years ago by rouault

  • status changed from new to closed
  • resolution set to invalid

I've commented a few lines in GDALtest.java but even in that case, I don't get any warnings. I'm not willing to spend more time on guessing what could be wrong on your local changes. As I said, I'd encourage you testing GDAL 1.7.0dev java bindings and report errors you could get with it.

Note: See TracTickets for help on using tickets.