Skip to content

Java SWIG - how to extract featureNames? #2814

Closed
@AlbertoEAF

Description

Hello,

I'm having issues calling the SWIG wrappers in Java to extract the model feature names.
I get a segmentation fault when calling LGBM_BoosterGetFeatureNames.

In the Java-exposed lightgbmJNI.LGBM_BoosterGetFeatureNames method, the parameters are:

LGBM_BoosterGetFeatureNames(long boosterHandle, long outNumFeaturesPtr, String[] strings)
(https://lightgbm.readthedocs.io/en/latest/C-API.html#c.LGBM_BoosterGetFeatureNames)

The issue is that LGBM_BoosterGetFeatureNames requires an already allocated array of strings on the C side, which I cannot do if I pass a java String[] object. This then results in a memory segfault.

I've seen this comment related to implementing typemaps in SWIG for trickier cases #909 (comment).

I also saw some notices in the swig interface file:
/* Note: there is a bug in the SWIG generated string arrays when creating a new array with strings where the strings are prematurely deallocated */ %array_functions(char *, stringArray)

Am I using the API incorrectly or currently this function cannot be used?

Thank you! :D

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