hypfvieh / dbus-java

Improved version of java DBus library provided by freedesktop.org (https://dbus.freedesktop.org/doc/dbus-java/)
https://hypfvieh.github.io/dbus-java/
MIT License
185 stars 73 forks source link

Unexporting object does not remove from introspection #80

Closed rm5248 closed 4 years ago

rm5248 commented 4 years ago

The following is a very simple minimum example of a DBus-Java program:

import org.freedesktop.dbus.connections.impl.DBusConnection;
import org.freedesktop.dbus.exceptions.DBusException;
import org.freedesktop.dbus.interfaces.DBusInterface;

public class ExportClass implements DBusInterface {

    @Override
    public boolean isRemote() {
        return false;
    }

    @Override
    public String getObjectPath() {
        return "/";
    }

    public static void main(String[] args) throws DBusException, InterruptedException{
        DBusConnection conn = DBusConnection.getConnection(DBusConnection.DBusBusType.SESSION);
        conn.requestBusName( "example.java.dbus" );

        ExportClass ex = new ExportClass();
        conn.exportObject( "/path", ex);

        System.out.println( "Exported object, waiting" );
        Thread.sleep( 5000 );

        conn.unExportObject( "/path" );
        System.out.println( "Unexported object, waiting" );

        Thread.sleep( 5000 );
        System.exit( 0 );
    }

}

When exporting the object, the new node at /path is properly shown in the introspection document, however after it is unexported the node will continue to show up. That is, introspecting results in the following document even if the object has been unexported:

$ qdbus example.java.dbus / org.freedesktop.DBus.Introspectable.Introspect
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node name="/">
<node name="path"/>
</node>

This is contrary to the DBus reference implementation - the path should be removed if it is unexported.

This looks like a problem with the ObjectTree class.