Code Monkey home page Code Monkey logo

dbus-java's People

Contributors

0mp avatar asamk avatar brett-smith avatar chris-melman avatar cthbleachbit avatar dependabot[bot] avatar drivera-armedia avatar erikvdijk77 avatar hypfvieh avatar lbeuster-cts avatar littlefreaky avatar mattdibi avatar mdoswaldschiller avatar michaelngv avatar mk868 avatar poeschel avatar prototik avatar rafalsumislawski avatar rano99 avatar rhwood avatar rm5248 avatar s5uishida avatar spannm avatar thjomnx avatar yveshydros avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dbus-java's Issues

Add Mac support

The current 3.0 tries to open a machine-id file in /var/lib/dbus/machine-id. The dbus daemon on mac (installed with the brew packagemanager - the default) uses /usr/local/var/lib/dbus/machine-id.

The address auto detection for Mac uses only the special Mac env var. Maybe it's good the try the special Mac var first and if not found fall back to the default var.

How to receive a DBusStuctType Variant

Hello,
I have a problem with reception of the Variant sent as signal argument.
The signature of MyStruct is "(byyyyyyyyyyyyssssssssuiqyiiiis)".

Creation and sending of this Variant works without any problems:
Variant v = new Variant( new MyStruct() );
or
Variant v = new Variant<>( new MyStruct() );

Reception:
The server requestSetMyStruct( Variant msVariant ) method shall receive, and unpack the Variant.
The type of the msVariant is DBusStructType so probably the signature of the method shall be:
requestSetMyStruct( Variant msVariant )

Anyway I am not able to convert the msVariant to MyStruct.

  • Is there any "simple" (as in the case of variant creation) method to convert the msVariant to MyStruct?

  • following the primitizeRecurse() method from the CrossTestClient.java I've tried:

    public MyStruct requestSetMyStruct( Variant msVariant ) {
    Object o = msVariant .getValue();
    Type t = msVariant .getType();

    if( t instanceof ParameterizedType ) {
    Class c = (Class) ((ParameterizedType) t).getRawType();

    if (Struct.class.isAssignableFrom(c)) {
      Object[] os = ((Struct) o).getParameters(); <<<<<<<<<< throws the InvocationTargetException Exception here
      Type[] ts = ((ParameterizedType) t).getActualTypeArguments();
    }
    

    }
    ...
    return ms;
    }

    Thank you for your help,
    with best regards,
    Bogdan

FileDescriptors don't actually get sent

This is marked as fixed in #42, however after some testing I have found that sending FileDescriptors does not actually work correctly.

I have some sample code here that demonstrates the issue. What I am trying to do is to create a pipe in a client application and send it to a different application in order to write to it. I create the pipe via JNA, and then attempt to convert it to a java.io.FileDescriptor in order to be sent. When I do that, dbus-monitor has the following output:

method call time=1573231344.276953 sender=:1.1897 -> destination=test.filedescriptor serial=3 path=/; interface=fd_rx.FDInterface; member=setFileDescriptor
   file descriptor
method return time=1573231344.298849 sender=:1.1895 -> destination=:1.1897 serial=5 reply_serial=3

On the receiving side, the file descriptor is parsed and is believed to be valid, however when we attempt to write to it we get an IOException:

[2019-11-08 11:42:24] DEBUG fd_rx.FDRX - Got the file descriptor.  Valid? true
[2019-11-08 11:42:24] ERROR fd_rx.FDRX - IOException: 
java.io.IOException: Bad file descriptor
	at java.io.FileOutputStream.write(Native Method) ~[?:1.8.0_171]
	at java.io.FileOutputStream.write(FileOutputStream.java:290) ~[?:1.8.0_171]
	at java.io.DataOutputStream.writeChars(DataOutputStream.java:297) ~[?:1.8.0_171]
	at fd_rx.FDRX.setFileDescriptor(FDRX.java:31) [classes/:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_171]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_171]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_171]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
	at org.freedesktop.dbus.connections.AbstractConnection$2.run(AbstractConnection.java:766) [dbus-java-3.2.0.jar:3.2.0]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_171]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_171]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_171]

I've also created a C++ application that uses dbus-cxx that acts the same as the Java application where it tries to send a FileDescriptor to the other process. This fails with an error, and the following shows up in dbus-monitor:

method call time=1573231622.504991 sender=:1.1900 -> destination=test.filedescriptor serial=2 path=/; interface=fd_rx.FDInterface; member=setFiledescriptor
   file descriptor
         inode: 42492471
         type: fifo
error time=1573231622.505026 sender=org.freedesktop.DBus -> destination=:1.1900 error_name=org.freedesktop.DBus.Error.NotSupported reply_serial=2
   string "Tried to send message with Unix file descriptorsto a client that doesn't support that."

It seems that the root of this problem is when a java.io.FileDescriptor is sent, an integer is simply marshaled onto the message, which is not the correct way to send a filedescriptor over a socket.

According to the DBus spec, the client must send a "NEGOTIATE_UNIX_FD Command" to allow FD passing. From my reading of the specification as well, it seems that after the NEGOTIATE_UNIX_FD has been sent, when you are actually sending the FD this needs to be set in the message header, and the FDs are sent as some kind of array(the spec indicates that they are sent out-of-band). The value of the FD set in the message is the index into this array.

CreateInterface chokes on DTD declaration

The command to build a java interface throws a fatal error.

prompt$ CreateInterface --system org.freedesktop.NetworkManager /org/freedesktop/NetworkManager
[Fatal Error] introspect.dtd:1:3: The markup declarations contained or pointed to by the document type declaration must be well-formed.

One solution, turn off DTD checking. Easily done with a few lines of code. See below.

/bbaker

-------CUT HERE-------------CUT HERE-------------CUT HERE----------

diff --git a/src/main/java/org/freedesktop/dbus/bin/CreateInterface.java b/src/main/java/org/freedesktop/dbus/bin/CreateInterface.java
index c1ca549..7ea5191 100644
--- a/src/main/java/org/freedesktop/dbus/bin/CreateInterface.java
+++ b/src/main/java/org/freedesktop/dbus/bin/CreateInterface.java
@@ -734,6 +734,14 @@
     */
     public void createInterface(Reader introspectdata) throws ParserConfigurationException, SAXException, IOException, DBusException {
         DocumentBuilderFactory lfactory = DocumentBuilderFactory.newInstance();
+        // FIXME: Option to remove validation and external DTD check
+        // http://stackoverflow.com/questions/155101/make-documentbuilder-parse-ignore-dtd-references
+        lfactory.setValidating(false);
+        lfactory.setNamespaceAware(true);
+        lfactory.setFeature("http://xml.org/sax/features/namespaces", false);
+        lfactory.setFeature("http://xml.org/sax/features/validation", false);
+        lfactory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
+        lfactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
         DocumentBuilder builder = lfactory.newDocumentBuilder();
         Document document = builder.parse(new InputSource(introspectdata));

InterfaceCodeGenerator doesn't support using an XML instrospection file

The deprecated CreateInterface class allows you to generate Java classes using XML introspection data as an input, so it does not need to access the DBus interface to do code generation.

The new InterfaceCodeGenerator always introspects the DBus directly and does not support using an XML introspection file.

This is important for cross-platform building.

DBusConnectionTest fails closing connection

Hi,

I just cloned the master branch and saw that the tests fails. In particular the DBusConnectionTest does not manage to close the connection at line reproduced below:

// after a close of conn1 the bus name should be available again
connection1.close();

Following the stack trace I was wondering if the following line in the class DBusConnection.java at line 983 is incorrect:

getExportedObjects().keySet().stream().filter(f -> f == null).forEach(key -> unExportObject(key));

and should be

getExportedObjects().keySet().stream().filter(f -> f != null).forEach(key -> unExportObject(key));

The stack trace of the error is

...
10:47:39.458 [DBus Worker Thread-1] DEBUG org.freedesktop.DBus$NameAcquired - Creating message with serial 9
10:47:39.460 [DBus Worker Thread-2] DEBUG org.freedesktop.DBus$NameAcquired - Creating message with serial 10
10:47:39.462 [DBus Worker Thread-1] DEBUG org.freedesktop.DBus$NameAcquired - Appending sig: yyyy data: [108, 4, 0, 1]
10:47:39.462 [DBus Worker Thread-2] DEBUG org.freedesktop.DBus$NameAcquired - Appending sig: yyyy data: [108, 4, 0, 1]
10:47:39.462 [DBus Worker Thread-1] DEBUG org.freedesktop.DBus$NameAcquired - Appending sig: ua(yv) data: [10, [[1, [o, /org/freedesktop/DBus]], [2, [s, org.freedesktop.DBus]], [3, [s, NameAcquired]], [8, [g, s]]]]
10:47:39.462 [DBus Worker Thread-2] DEBUG org.freedesktop.DBus$NameAcquired - Appending sig: ua(yv) data: [11, [[1, [o, /org/freedesktop/DBus]], [2, [s, org.freedesktop.DBus]], [3, [s, NameAcquired]], [8, [g, s]]]]
10:47:39.465 [DBusConnection] DEBUG org.freedesktop.dbus.MessageReader - => MethodReturn(1,4294967295) { Reply Serial=>11, Destination=>:1.406, Sender=>org.freedesktop.DBus, Signature=>u } { 3 }
10:47:39.469 [DBusConnection] DEBUG org.freedesktop.dbus.MessageReader - => DBusSignal [clazz=null]
10:47:39.469 [DBusConnection] DEBUG org.freedesktop.dbus.MessageReader - => MethodReturn(1,4294967295) { Reply Serial=>12, Destination=>:1.405, Sender=>org.freedesktop.DBus, Signature=>u } { 1 }
10:47:39.470 [DBusConnection] DEBUG org.freedesktop.dbus.MessageReader - => MethodReturn(1,4294967295) { Reply Serial=>13, Destination=>:1.405, Sender=>org.freedesktop.DBus, Signature=>u } { 2 }


java.lang.NullPointerException
	at org.freedesktop.dbus.messages.ObjectTree.recursiveFind(ObjectTree.java:58)
	at org.freedesktop.dbus.messages.ObjectTree.remove(ObjectTree.java:128)
	at org.freedesktop.dbus.connections.AbstractConnection.unExportObject(AbstractConnection.java:362)
	at org.freedesktop.dbus.connections.impl.DBusConnection.lambda$disconnect$9(DBusConnection.java:983)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
	at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
	at java.base/java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1605)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
	at org.freedesktop.dbus.connections.impl.DBusConnection.lambda$disconnect$10(DBusConnection.java:983)
	at org.freedesktop.dbus.connections.AbstractConnection.disconnect(AbstractConnection.java:510)
	at org.freedesktop.dbus.connections.impl.DBusConnection.disconnect(DBusConnection.java:987)
	at org.freedesktop.dbus.connections.impl.DBusConnection.close(DBusConnection.java:996)
	at org.freedesktop.dbus.test.DBusConnectionTest.test_busnames_should_be_auto_released_on_close_of_non_shared_connection(DBusConnectionTest.java:42)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:675)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:125)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:132)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:124)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:74)
	at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:104)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:62)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:43)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:35)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:202)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:198)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:69)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1507)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1507)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229)
	at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197)
	at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)

dbus-java-dbus-java-parent-3.0.2 installation

Hello,
I am going to install and evaluate the dbus-java-dbus-java-parent-3.0.2.
The "mvn test" seems to work (with some small errors).
Then I've noticed the two almost identical directories:
./dbus-java/src/main/resources/
and
./dbus-java/target/classes/
with Makefiles.

In the INSTALL file in these directories it is stated, that for the successful compilation, the http://www.matthew.ath.cx/projects/java/ libraries are necessary.

I thought, these libraries are part of the old implementation (2.7.x versions), which in turn in not compatible (according to the README.md file) with this library.

Could you please explain the dependencies between the project and these two directories and describe the steps of the full installation?

Thank you for your help,

with best regards,

Bogdan

On wiring up continuous integration amongst other things

Hey Guys! You got a jump start on the very thing I've been meaning to do for some time now ;) Is this project still active? I see 1 release but nothing else. Maybe just nothing new to add? In either event, and with interest in dbus-broker getting more attention, we've got a need to bring this project up to snuff with continuous integration support, releases deployed to jcenter, a pure gradle build and all that comes with that, and more regular releases. Is this something this project would be up for or are we better off forking it? I maintain a hand full of other projects perhaps most notably the gradle-docker-plugin and we'd like to do something very similar here to what we did there.

AbstractConnection.changeThreadCount() is fragile

The AbstractConnection.changeThreadCount() method is fragile since 3.x

  1. A local var for workerThreadCount should be inroduced. Now a change to 3 and back to 4 would leave the worker count at 3 - or remove the check of old and new count at all.

  2. There is a small time window when no valid executor is available, the old already shutdown, the new not created yet. This (eventually in combination with the next point 3.) results in

org.freedesktop.dbus.connections.AbstractConnection$3@7a720633 rejected from java.util.concurrent.ThreadPoolExecutor@5855cbc6[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]
	at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2063)
	at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:830)
	at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1379)
	at org.freedesktop.dbus.connections.AbstractConnection.handleMessage(AbstractConnection.java:834)
	at org.freedesktop.dbus.connections.AbstractConnection.handleMessage(AbstractConnection.java:615)
	at org.freedesktop.dbus.connections.IncomingMessageThread.run(IncomingMessageThread.java:43)

The stack trace is from 3.0.2, where the error occurred much more than in the current 3.2.0-SNAPSHOT.
Could be fixed with the following code, but may change the order of the executed tasks (which should not matter anyway):

ExecutorService oldWorkerThreadPool = this.workerThreadPool; 
this.workerThreadPool =  Executors.newFixedThreadPool(newcount, ...);
List<Runnable> remainingTasks = oldWorkerThreadPool.shutdownNow();
  1. Since the workerThreadPool reference is mutable and shared across different threads it should be an AtomicReference (or volatile).

Receive arbitrary signals

For a project that I'm working on, I need to have the ability to listen to arbitrary signals on the bus. A few years ago, I patched dbus-java(2.7) to give it this capability. I just tried with the current version of dbus-java and it won't work correctly, due to how signals work(you need to create a class in the correct package for it to be called correctly). Two questions with this:

  1. Does this make sense as a feature to add? It's needed for my case, but I don't know if it makes sense to add to the library. Most other dbus implementations do provide a way to listen to arbitrary signals.
  2. Assuming it makes sense, the way that I implemented it before was to add in AbstractConnection a new variable for the custom signals, the same type as handledSignals and then looks at these custom handlers after looking at the normal(typed) handlers.

I can do the implementation, I just wanted to get feedback before I started on this.

Probably need "sun.misc" import declaration in pom.xml

I haven't confirmed the operation, but I think that "sun.misc" import declaration probably needs to be added in dbus-java-osgi/pom.xml.

<Import-Package> org.slf4j,
==>  sun.misc,
    org.eclipse.jdt.annotation;resolution:=optional 
</Import-Package>

When I checked bluez-dbus on OSGi, jnr-unixsocket depended on sun.misc, so the same situation will occur.

Ignored Exceptions

image

This code smells badly. Exceptions are blatantly ignored, presumably because they should actually be RuntimeExceptions...

dbus & bluez - сharacteristic notification

Hello to all!

Please help with the following problem. Mobile application does not receive сharacteristic notification. So I have an application that successfully writes and reads characteristic. To a specific characteristic, I added the flag 'notify'

For notification, I do this:

Map<String, Variant<?>> dict = new HashMap<>();
dict.put("Value", new Variant<>("hello".getBytes()));
Properties.PropertiesChanged message = new Properties.PropertiesChanged("/service/ble/service0/char0", "org.bluez.GattCharacteristic1", dict, new ArrayList<>());
connection.sendMessage(message);

dbus-monitor:

signal time=1570341966.172522 sender=:1.526 -> destination=(null destination) serial=41 path=/service/ble/service0/char0; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.bluez.GattCharacteristic1"
   array [
      dict entry(
         string "Value"
         variant             array of bytes "hello"
      )
   ]
   array [
   ]

But on a mobile device, notification does not occur

Please tell me what can I do wrong?
It confuses me a little that there is no device in the request to which the notification is sent. But I don’t understand how to set it (/org/bluez/hci0/dev_14_9F_3C_2F_C0_18)

DBusConnection.close() should release requested bus names

I think a non shared connection should release any requested busnames on close(). With 2.7.x it still worked. With 3.2.x not (don't know the state of 3.0.x).

I created a pull request (#61) with a failing test case.

BTW: It only fails on Ubuntu and passes on Mac.

Potential leak of application internals in ExportedObject.getAnnotations()

If a DBusInterface adds any class-level annotations that have a value() method, even if they do not pertain to DBus itself, they will get leaked as introspection data to any clients that care.

In the case of an annotation including information pertaining to implementation details (including crypto suites, hard-coded hostnames, etc.) this information would be freely transmitted to the user.

This is because ExportedObject.getAnnotations() does not filter which annotations it includes in the introspection data:

https://github.com/hypfvieh/dbus-java/blob/master/src/main/java/org/freedesktop/dbus/messages/ExportedObject.java#L56-L67

Arbitrary signals with no interface

With some of the previous arbitrary signals improvements, it's now possible to send and receive signals. This works fine for most use cases that I've encountered so far, but I've found a new use case where I'm only interested in listening to a signal with a type, member, and object(e.g. the AddMatch method to the DBus-daemon is type='signal',member='mymember','path=/'. In code, this is new DBusMatchRule( "signal", null, "mymember", "/")) This results in no callbacks being called, as the code for handling this assumes that there is always an interface.

I was considering adding a new block to the if statement(something like this:)

t = getGenericHandledSignals().get(new SignalTuple(null, _signal.getName(), _signal.getPath(), null));
if( null != t ) ...

However, this seems like it could easily get out of hand given the possible combinations of parts of the signal that could be null(4! = 24). Is there a better way to do this, or should I simply add some more statements to this block?

2.7.5

I see you are working on a new 3.0 version, which is great :)
but I would appreciate if you would publish a 2.7.5 version to maven, since I am writing a mpris-java library based on this work and encounter the recently fixed issues

Exception in connection thread when connection timeout is triggered in Linux environment

Not sure this has been noticed by others. I am using dbus-java in Ubuntu 16.04 64-bit VM. This API has been used
public static DBusConnection getConnection(DBusBusType _bustype)
According to the code, the default AbstractConnection.TIMEOUT, which is 100 second, will be applied. However, when the timeout is triggered, the connection thread is throwing an exception like
2019-04-29 16:31:40.351 [FINE ] [org.freedesktop.dbus.connections.AbstractConnection disconnect] - Disconnecting Abstract Connection 2019-04-29 16:31:40.351 [FINE ] [org.freedesktop.dbus.connections.transports.UnixSocketTransport close] - Disconnecting Transport 2019-04-29 16:31:40.352 [FINEST ] [org.freedesktop.dbus.MessageReader close] - Closing Message Reader 2019-04-29 16:31:40.352 [FINE ] [org.freedesktop.dbus.MessageWriter close] - Closing Message Writer 2019-04-29 16:31:40.352 [SEVERE ] [org.freedesktop.dbus.connections.IncomingMessageThread run] - Exception in connection thread. org.freedesktop.dbus.exceptions.FatalDBusException: Underlying transport returned EOF (1) at org.freedesktop.dbus.connections.AbstractConnection.readIncoming(AbstractConnection.java:1048) at org.freedesktop.dbus.connections.IncomingMessageThread.run(IncomingMessageThread.java:39)

I suppose this is not an expected behavior. In order to continue to use dbus-java in my project, I have to use the other getConnection API which allows setting timeout to 0.

Any thoughts and suggestions regards this issue? Many thanks.

Close Dbus connection withdraw Name from registry

Hi,

I have the following use case :
I have describe a systemD dbus service.
It launches some java app.
When java app start up is done, i establish Dbus connection and use Dbus object to registre Name.
When it is done I close the dbus connection because it allocates Thread that will no more be used. As side effect, i see that it withdraw the name from Dbus registry.

All works perfectly with systemD in version 229.

I update systemD to version 239 and now the service start but it is immediatly killed. With some test it is clearly link to the Dbus withdraw side effect.

The withdraw is mandatory ?
Can i stop Dbus connection without the withdraw ?

Using on MacOS

I saw the Add Mac support was addressed but what is the best way to create a library? I tried running the compile_native.sh and setting target and base dir but it's looking for many libraries. I'd appreciate any help in creating a library.

DBusConnection timeout

During the creation of a dbus connection I can pass a timeout. After that timeout of inactivity on the connection it dies (and never reconnects since it's fatal) with:

15:51:27.766 [DBusConnection] ERROR o.f.d.c.IncomingMessageThread - FatalException in connection thread.
org.freedesktop.dbus.exceptions.FatalDBusException: Underlying transport returned EOF (1)
	at org.freedesktop.dbus.connections.AbstractConnection.readIncoming(AbstractConnection.java:1102)
	at org.freedesktop.dbus.connections.IncomingMessageThread.run(IncomingMessageThread.java:39)

I guess that's not expected?

Can be reproduced on any test by setting a breakpoint after connection creation (default timeout is 100 sek).

InterfaceCodeGenerator implementation example

Hi,

I find no where an example of the usage of the new way to create DBus Objects using the InterfaceCodeGenerator class. Could you guide me in finding a way to for example question the NetworkManager dbus object?

Incorrect imports generated by CreateInterface

CreateInterface generates code using some hard coded imports that refer to the old package names for some refactored classes, including:

In createException:
out.println("import org.freedesktop.dbus.DBusExecutionException;");

In createTuple():
out.println("import org.freedesktop.dbus.Position;");

These should be:
out.println("import org.freedesktop.dbus.exceptions.DBusExecutionException;");
out.println("import org.freedesktop.dbus.annotations.Position;");

Possibility to disable share dbus connection cache during connection creation

Currently there are only static methods to get a dbus connection. These methods use a static map that return always the same connection instance for the same address. Especially in tests where you simulate server and client this is not a good idea.
I would be nice to create independant dbus connections.

  • One simple solution could be to make the constructor DBusConnection.(address, registerSelf) public. And extract the auto detection code to a static method. Client code would look like
connection = new DBusConnection(DBusConnection.autoDetectAddress(SESSION), false);
  • Another could be to add more factory methods. Perhaps getConnection-methods that use the static map and newConnection methods that always create a new connection

What do you think? If we have a decision I could create a pull request.

Erroneous type deserialization on some signals

I am listening to some signals from DBus, one of them is "ServicesChanged" from Connman, which has a signature of a(oa{sv})ao.

It seems that the signals that have the first array as empty, and the other array (of object paths) non-empty, result in a ClassCastException:

2018-07-19 08:17:52 [DBus Worker Thread-3] WARN  o.f.d.c.impl.DBusConnection - Exception while running signal handler 'xxx.ConfigurationService$ServicesChangeHandler@38db2f' for signal 'DBusSignal [clazz=class xxx.IDBusConnmanManager$ServicesChanged]': {}
org.freedesktop.dbus.exceptions.DBusException: java.lang.IllegalArgumentException: java.lang.ClassCastException@1858f7
	at org.freedesktop.dbus.messages.DBusSignal.createReal(DBusSignal.java:222)
	at org.freedesktop.dbus.connections.AbstractConnection$3.run(AbstractConnection.java:772)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalArgumentException: java.lang.ClassCastException@1858f7
	at sun.reflect.GeneratedConstructorAccessor22.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.freedesktop.dbus.messages.DBusSignal.createReal(DBusSignal.java:215)
	... 4 common frames omitted

What seems to happen is that while getting the signal constructor parameters in Message.getParameters(), the array of object paths is interpreted as one object path (the one path value is all the object path strings mangled together plus some garbage inbetween). Then when giving the parameters to Reflection, an exception is thrown as the wrongly deserialized constructor param is ObjectPath and not List<ObjectPath>.

2018-07-19 15:38:20 [DBus Worker Thread-1] TRACE o.f.dbus.messages.DBusSignal - extract(a(oa{sv})ao,#1194, {0,0}
2018-07-19 15:38:20 [DBus Worker Thread-1] TRACE o.f.dbus.messages.DBusSignal - Extracting type: a from offset 0
2018-07-19 15:38:20 [DBus Worker Thread-1] TRACE o.f.dbus.messages.DBusSignal - aligning to a
2018-07-19 15:38:20 [DBus Worker Thread-1] TRACE o.f.dbus.messages.DBusSignal - Reading array of size: 0
2018-07-19 15:38:20 [DBus Worker Thread-1] TRACE o.f.dbus.messages.DBusSignal - aligning to (
2018-07-19 15:38:20 [DBus Worker Thread-1] TRACE o.f.dbus.messages.DBusSignal - Aligned type: (oa{sv})ao 8 9
2018-07-19 15:38:20 [DBus Worker Thread-1] TRACE o.f.dbus.messages.DBusSignal - Extracted: [] (now at 8)
2018-07-19 15:38:20 [DBus Worker Thread-1] TRACE o.f.dbus.messages.DBusSignal - Extracting type: o from offset 8
2018-07-19 15:38:20 [DBus Worker Thread-1] TRACE o.f.dbus.messages.DBusSignal - aligning to o
2018-07-19 15:38:20 [DBus Worker Thread-1] TRACE o.f.dbus.messages.DBusSignal - Extracted: I/net/connman/service/wifi_80d21d5f4569_42656c6b696e2e35333945_managed_psk>/net/connman/service/wifi_80d21d5f4569_4755455354_managed_noneU/net/connman/service/wifi_80d21d5f4569_416c6578616e64657273206950686f6e65_managed_pskQ/net/connman/service/wifi_80d21d5f4569_434552545f55505f54455354_managed_ieee8021xQ/net/connman/service/wifi_80d21d5f4569_4c414e2d4e41432d54455354_managed_ieee8021xA/net/connman/service/wifi_80d21d5f4569_4853532d444556_managed_pskE/net/connman/service/wifi_80d21d5f4569_4b6f6e666572656e7a_managed_pskA/net/connman/service/wifi_80d21d5f4569_4553583547487a_managed_psk=/net/connman/service/wifi_80d21d5f4569_4553455854_managed_pskC/net/connman/service/wifi_80d21d5f4569_4553494e54_managed_ieee8021x?/net/connman/service/wifi_80d21d5f4569_776c6e6c6368_managed_psk?/net/connman/service/wifi_80d21d5f4569_hidden_managed_ieee8021x?/net/connman/service/wifi_80d21d5f4569_4c414e_managed_ieee8021x9/net/connman/service/wifi_80d21d5f4569_455358_managed_psk9/net/connman/service/wifi_80d21d5f4569_52494f_managed_pskE/net/connman/service/wifi_80d21d5f4569_434755455354_managed_ieee8021x (now at 1195)

Specifically, after having parsed the empty first array, the second round of extractOne method for the non-empty object path array is given an offset array which seems to have its first element (signature offset) one element too far and this makes the method try to parse an array of object paths as one. Hence the first round of extractOne of the two seems to update the offset to a value one too many. When I debug and set the signature offset to a value one less for extractOne after extracting the empty array, the parameters are deserialized correctly.

This is happening in (little-endian) signals with this exact signature, in 2.7.* and 3.0 both.

DBusConnection.getConnection error

I use Netbean , i add dbus-java dependency to pom.xml , the version is 3.0.2.

When i call the function below:
DBusConnection.getConnection(DBusBusType.SESSION, false, 100000);

There is an error:

no suitable method found for getConnection(DBusBusType,boolean,int)
method DBusConnection.getConnection(String,boolean,boolean) is not applicable
(argument mismatch; DBusBusType cannot be converted to String)
method DBusConnection.getConnection(Supplier,boolean,boolean) is not applicable
(argument mismatch; DBusBusType cannot be converted to Supplier)

I check the file, dbus-java/src/main/java/org/freedesktop/dbus/connections/impl/DBusConnection.java
there is :
public static DBusConnection getConnection(DBusBusType _bustype, boolean _shared, int _timeout)

Why the function does not match ?

dbus-java and NetworkManager

Hi,

since days I try to get dbus-java and and networkmanager up and running, without the final success. I hope that somebody of you can help me.

the task is simple: connect via dbus to the locally installed networkmanager, first list the devices, access detail information (here i fail), afterwards install signals handlers ..

my test script

public void dbustest()
	{
		DBusConnection conn; 
		Properties nmProp;
		NetworkManager na;
		
		try
		{
		 conn = DBusConnection.getConnection(DBusConnection.SYSTEM);	 
		 for (int i=0;i<conn.getNames().length;i++)
		 {
			 log.info("name={}",conn.getNames()[i]);
	  	 }
			
		 
		na=(NetworkManager) conn.getRemoteObject("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager",NetworkManager.class);
		 
		Map<String,String> myperm=na.GetPermissions();
		for (String s:myperm.keySet())
		{
			log.info("perm {}={}",s,myperm.get(s));
		}
		
		
	
		List<DBusInterface> devices=na.GetDevices();
		//List<Path> devices = na.GetDevices();
		log.info("devices={}",devices.size());
		
		
		
			///List<DBusInterface> mydevices=na.GetDevices();
		    //	List<Path> devList = na.GetDevices();
			//https://github.com/Paxle/Paxle/blob/master/bundles/Dbus/src/main/java/org/freedesktop/NetworkManager.java
		
			if (devices!=null)
			{
				for (DBusInterface i:devices)
				{
					//Path p=new Path();		
					//log.info("dbusinterface {}={}",i.toString(),d.hashCode());
					
				}
			}else
			{
				log.error("mydevices==null");
			}
		
		} catch (org.freedesktop.dbus.exceptions.DBusException e)
		{
			log.error("dbusException e={}",e);
		}
	}

my pom.xml

     <dependency>
          <groupId>com.github.hypfvieh</groupId>
        <artifactId>dbus-java</artifactId>
        <version>2.7.5</version>
        </dependency>

My Challenges / and the most recent ways i tried to fix them

Task1: Generation of the Java Interfaces
I installed the latest NetworkManager Source to get the introspection.xml files
I generated the neccesary Classes

/home/mf/dbus/hypf/dbus-java/target/classes/CreateInterface.sh -f /home/mf/dbus/NetworkManager/introspection/org.freedesktop.NetworkManager.xml
WARNING: Ignoring property
WARNING: Ignoring property
WARNING: Ignoring property
WARNING: Ignoring property
...
/home/mf/dbus/hypf/dbus-java/target/classes/CreateInterface.sh -f /home/mf/dbus/NetworkManager/introspection/org.freedesktop.NetworkManager.Device.Wired.xml
WARNING: Ignoring property
WARNING: Ignoring property
...

Question 1: Why do I get the Ignoring Property ? Any Relevance for me?
Question 2: Obviously the Source Generator uses ident PackageNames and ClassName which leads to the fllowing Comiliation Error - how can I overcome this beahviour?

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project quattro: Compilation failure: Compilation failure:
[ERROR] /home/mf/jooby/quattro/src/main/java/org/freedesktop/NetworkManager/Device/Wired.java:[1,1] package org.freedesktop.NetworkManager clashes with class of same name
[ERROR] /home/mf/jooby/quattro/src/main/java/org/freedesktop/NetworkManager.java:[12,8] interface org.freedesktop.NetworkManager clashes with package of same name

To solve this issue I moved the Wired (and the other classes which I generated but not listed here) to the top Level Package (for testing issues).

The good News I can compile and run the program, Connection to Dbus works

[2018-08-15 09:09:10,127]-[Hotswap] INFO  quattro.networkmanager.NetworkmanagerModule - networkmanagermodule start
[2018-08-15 09:09:10,219]-[Sender] INFO  org.freedesktop.dbus.MessageWriter - <= MethodCall(0,1) { Path=>/org/freedesktop/DBus, Interface=>org.freedesktop.DBus, Member=>Hello, Destination=>org.freedesktop.DBus } { }
[2018-08-15 09:09:10,225]-[Hotswap] INFO  quattro.networkmanager.NetworkmanagerModule - name=:1.156
[2018-08-15 09:09:10,239]-[Sender] INFO  org.freedesktop.dbus.MessageWriter - <= MethodCall(0,3) { Path=>/org/freedesktop/NetworkManager, Interface=>org.freedesktop.NetworkManager, Member=>GetPermissions, Destination=>org.freedesktop.NetworkManager } { }
[2018-08-15 09:09:10,261]-[Hotswap] INFO  quattro.networkmanager.NetworkmanagerModule - perm org.freedesktop.NetworkManager.enable-disable-network=no
[2018-08-15 09:09:10,261]-[Hotswap] INFO  quattro.networkmanager.NetworkmanagerModule - perm org.freedesktop.NetworkManager.enable-disable-wifi=no
[2018-08-15 09:09:10,262]-[Hotswap] INFO  quattro.networkmanager.NetworkmanagerModule - perm org.freedesktop.NetworkManager.enable-disable-wimax=no
[2018-08-15 09:09:10,262]-[Hotswap] INFO  quattro.networkmanager.NetworkmanagerModule - perm org.freedesktop.NetworkManager.enable-disable-wwan=no
[2018-08-15 09:09:10,262]-[Hotswap] INFO  quattro.networkmanager.NetworkmanagerModule - perm org.freedesktop.NetworkManager.network-control=no
[2018-08-15 09:09:10,262]-[Hotswap] INFO  quattro.networkmanager.NetworkmanagerModule - perm org.freedesktop.NetworkManager.settings.modify.hostname=auth
[2018-08-15 09:09:10,262]-[Hotswap] INFO  quattro.networkmanager.NetworkmanagerModule - perm org.freedesktop.NetworkManager.settings.modify.own=auth
[2018-08-15 09:09:10,262]-[Hotswap] INFO  quattro.networkmanager.NetworkmanagerModule - perm org.freedesktop.NetworkManager.settings.modify.system=auth
[2018-08-15 09:09:10,262]-[Hotswap] INFO  quattro.networkmanager.NetworkmanagerModule - perm org.freedesktop.NetworkManager.sleep-wake=no
[2018-08-15 09:09:10,262]-[Hotswap] INFO  quattro.networkmanager.NetworkmanagerModule - perm org.freedesktop.NetworkManager.wifi.share.open=no
[2018-08-15 09:09:10,262]-[Hotswap] INFO  quattro.networkmanager.NetworkmanagerModule - perm org.freedesktop.NetworkManager.wifi.share.protected=no
[2018-08-15 09:09:10,263]-[Sender] INFO  org.freedesktop.dbus.MessageWriter - <= MethodCall(0,4) { Path=>/org/freedesktop/NetworkManager, Interface=>org.freedesktop.NetworkManager, Member=>GetDevices, Destination=>org.freedesktop.NetworkManager } { }
[2018-08-15 09:09:10,267]-[Sender] INFO  org.freedesktop.dbus.MessageWriter - <= MethodCall(0,5) { Path=>/org/freedesktop/NetworkManager/Devices/0, Interface=>org.freedesktop.DBus.Introspectable, Member=>Introspect, Destination=>:1.50 } { }
[2018-08-15 09:09:10,284]-[Sender] INFO  org.freedesktop.dbus.MessageWriter - <= MethodCall(0,6) { Path=>/org/freedesktop/NetworkManager/Devices/1, Interface=>org.freedesktop.DBus.Introspectable, Member=>Introspect, Destination=>:1.50 } { }
[2018-08-15 09:09:10,289]-[Hotswap] INFO  quattro.networkmanager.NetworkmanagerModule - devices=2

Task2: Accessing Detail Information per Interface

As listed above the System seems to get the Information but only if I call

	List<DBusInterface> devices=na.GetDevices();

and DBusInterface has no properties or Methods to get Details. After Goolge Recherche I Found that the GetDevices (in some Implementations) returns List but thats not the case in my installation. Even a Cast to (eg. Device.Wired) does not work

Question3: What is the proposed way to access the Details in the resolved DbusInterface?

Thanks

Martin

Match rules leak when using addSigHandler/removeSigHandler

In the DBusConnection class, the method addSigHandler (line 875) adds a match rule to the DBus interface by calling AddMatch unconditionally and puts the handler to the internal map used to keep track of the signal handlers.
The method removeSigHandler (line 779) removes the signal handler from the internal map, but only calls RemoveMatch on the DBus interface if no other handler is in the map which matches the same SignalTuple.

This asymmetry causes a match rule leak when adding and removing multiple signal handlers which result in the same SignalTuple value.
In my case, the application adds and removes handlers depending on state information. After some time, adding new match rules will fail because the maximum number of allowed rules is reached.

InterfaceCodeGenerator appears to generate Java code with errors

I hope this is just my experience or I was using the code improperly in some way. I tried to generate the Java interface for wireless but encountered the following in the generated code:

  • the package declaration is package org.freedesktop.networkmanager.device; -- wrong case on networkmanager and device.
  • The data members _path and _interfaceName are referenced but not declared.
  • The data member properties is sometimes referenced as _properties.

3.0 release timetable

Hi ! Just a couple of questions.

  • Is there any planned release date for version 3.0.0 ?
  • Current 3.0.0-SNAPSHOT status - compared to 2.7.5, is it usable already (feature complete / no showstopper bugs / etc.) ?

Cheers

Message toString does not handle nulls

This is a snippet from the toString method of Message.java:

            for (Object o : largs) {
                if (o instanceof Object[]) {
                    sb.append(Arrays.deepToString((Object[]) o));
                } else if (o instanceof byte[]) {
                    sb.append(Arrays.toString((byte[]) o));
                } else if (o instanceof int[]) {
                    sb.append(Arrays.toString((int[]) o));
                } else if (o instanceof short[]) {
                    sb.append(Arrays.toString((short[]) o));
                } else if (o instanceof long[]) {
                    sb.append(Arrays.toString((long[]) o));
                } else if (o instanceof boolean[]) {
                    sb.append(Arrays.toString((boolean[]) o));
                } else if (o instanceof double[]) {
                    sb.append(Arrays.toString((double[]) o));
                } else if (o instanceof float[]) {
                    sb.append(Arrays.toString((float[]) o));
                } else {
                    sb.append(o.toString());
                }
                sb.append(',');
                sb.append(' ');
            }

When I used 2.7.5, this regularly throwed a NullPointerException for me since o was apparently null in some cases. I haven't had the Exception after upgrading to version 3, but I am unsure whether it is correct to not handle null here.
Even if o can never be null you should add a little Objects.requireNonNull or something to catch potential problems immediately.

Make dbus-java OSGi ready

Hi David,

First of all thanks for this library, it is very helpful if you want to connect to DBus.

Now, checking the MANIFEST file of v3.0.0 jar file in the maven repository, I could see that there are not any metadata specific for an OSGi bundle, like Import-Package, Export-Package, etc. Are you considering to add them in a later release?

Regards,

Stavros

CreateInterface for firewalld Creates Class / Package Name clash

Running CreateInterface to create code for the object path '/org/fedoraproject/FirewallD1` creates
a Java class org.fedoraproject.FirewallD1.java whose name is the same as a java package, so the code
does not compile.

Also: the imports for DBusInterface and DBusSignal need to reflect the new package locations for these.

Cannot connect to pulse bus

I've been trying to connect to the pulseaudio dbus server with this code:

DBusConnection sessionConnection = DBusConnection.getConnection(DBusConnection.SESSION);
DBus.Properties properties = sessionConnection.getRemoteObject("org.pulseaudio.Server", "/org/pulseaudio/server_lookup1", DBus.Properties.class);
String address = properties.Get("org.PulseAudio.ServerLookup1", "Address");
sessionConnection.disconnect();

connection = DBusConnection.getConnection(address);

but it keeps failing with the following exception at the last line:

org.freedesktop.dbus.exceptions.DBusException: Method "Hello" with signature "" on interface "org.freedesktop.DBus" doesn't exist
  at org.freedesktop.dbus.DBusConnection.<init>(DBusConnection.java:374)
  at org.freedesktop.dbus.DBusConnection.getConnection(DBusConnection.java:239)

DBusConnection fails with certain locales (e.g. Turkish)

When the default locale of the JVM is set to Turkish, it is not possible to open any DBus connection (may also happen with other locales). The exception is:

Caused by: org.freedesktop.dbus.exceptions.DBusException: Unsupported transport type: unix
	at org.freedesktop.dbus.connections.BusAddress.<init>(BusAddress.java:43)
	at org.freedesktop.dbus.connections.AbstractConnection.<init>(AbstractConnection.java:144)

This exception is catched in the AbstractConnection constructor and the disconnect() method is called which causes another NPE and loses the stacktrace of the original exception:

org.freedesktop.dbus.exceptions.DBusException: Failed to connect to bus Unsupported transport type: unix
	at org.freedesktop.dbus.connections.AbstractConnection.<init>(AbstractConnection.java:150)
	at org.freedesktop.dbus.connections.impl.DBusConnection.<init>(DBusConnection.java:274)
	at org.freedesktop.dbus.connections.impl.DBusConnection.getConnection(DBusConnection.java:115)

The root cause of this problem is that the toLowerCase() method (without locale parameter) is used in the class AddressBusTypes. This causes the toEnum method to fail for certain locales because e.g. the lower case version of the enum constant UNIX for the Turkish locale is unıx instead of unix and therefore the lookup fails.

This can be fixed by using toLowerCase(Locale.ROOT) to convert non language dependent (e.g. technical) text to lower case.

Variant of Map

First off: thanks for this great piece of work and the improvements coming in during the last couples of month. We're now using version 3.2.0.

I'm currently working on a java facade for connman (and ofono) and I'm facing the following issue:

The API for DBus interface net.connman.Service is described here https://github.com/aldebaran/connman/blob/master/doc/service-api.txt

The interface has a method SetProperty(string name, variant value). I want to pass a new IPv4.Configuration. The internal type of that value is dict, that should be defined in a Map<String, Variant<?>. By contract I need to define a Variant like new Variant(map) to pass it to the call of SetProperty. Doing this results in an exception with the following message:

Exception in thread "main" java.lang.IllegalArgumentException: Can't wrap class java.util.HashMap in an unqualified Variant (Exporting non-exportable type: class java.util.HashMap).
        at org.freedesktop.dbus.types.Variant.<init>(Variant.java:54)

How would you solve this?

No reply from invoking method

Hi,

I'm trying to access a service via dbus using your library. I am right now a bit stuck as the method which I am invoking is running into a "No reply within specified time" error. To narrow the issue down I first wanted to know whether my test code is correct.

My simple test code looks as follows:
`public class Main {

public static void main(String[] args) {

    try (DBusConnection dbus = DBusConnection.getConnection(DBusConnection.DBusBusType.SYSTEM);) {

        dbus.requestBusName("at.valli.mesh");

        String busName = "org.bluez.mesh";
        String objectPath = "/org/bluez/mesh";
        Network1 mesh = dbus.getRemoteObject(busName, objectPath, Network1.class);

        TestApplication application = new TestApplication();
        dbus.exportObject(application.getObjectPath(), application);
        TestElement element1 = new TestElement(application.getObjectPath(), (byte) 0);
        TestElement element2 = new TestElement(application.getObjectPath(), (byte) 1);
        dbus.exportObject(element1.getObjectPath(), element1);
        dbus.exportObject(element2.getObjectPath(), element2);

        UUID uuid = UUID.randomUUID();

        mesh.Join(application, UUIDs.toBytes(uuid));

        Thread.sleep(30000);

        dbus.releaseBusName("at.valli.mesh");

    } catch (NoReply | DBusException | IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

}`

and the corresponding log output is as follows:

`13:18:05,277 DEBUG [main] o.f.d.c.Transport: Connecting to UNIX: {path=/var/run/dbus/system_bus_socket}
13:18:05,466 DEBUG [main] o.f.d.m.MethodCall: Creating message with serial 1
13:18:05,469 DEBUG [main] o.f.d.m.MethodCall: Appending sig: yyyy data: [66, 1, 0, 1]
13:18:05,470 DEBUG [main] o.f.d.m.MethodCall: Appending sig: ua(yv) data: [1, [[1, [o, /org/freedesktop/DBus]], [6, [s, org.freedesktop.DBus]], [2, [s, org.freedesktop.DBus]], [3, [s, Hello]]]]
13:18:05,471 DEBUG [main] o.f.d.m.MethodCall: Appended body, type: null start: 128 end: 128 size: 0
13:18:05,471 DEBUG [main] o.f.d.m.MethodCall: marshalled size ([0, 0, 0, 0]): 000000 00 00 00 00 ....

13:18:05,476 DEBUG [DBus Sender Thread-1] o.f.d.MessageWriter: <= MethodCall(0,1) { Path=>/org/freedesktop/DBus, Interface=>org.freedesktop.DBus, Member=>Hello, Destination=>org.freedesktop.DBus } { }
13:18:05,484 DEBUG [DBusConnection] o.f.d.MessageReader: => MethodReturn(1,1) { Reply Serial=>1, Destination=>:1.73, Sender=>org.freedesktop.DBus, Signature=>s } { :1.73 }
13:18:05,485 DEBUG [DBusConnection] o.f.d.c.i.DBusConnection: Handling incoming method return: MethodReturn(1,1) { Reply Serial=>1, Destination=>:1.73, Sender=>org.freedesktop.DBus, Signature=>s } { :1.73 }
13:18:05,485 DEBUG [main] o.f.d.m.MethodCall: Creating message with serial 2
13:18:05,486 DEBUG [main] o.f.d.m.MethodCall: Appending sig: yyyy data: [66, 1, 0, 1]
13:18:05,486 DEBUG [main] o.f.d.m.MethodCall: Appending arguments with signature: su
13:18:05,487 DEBUG [main] o.f.d.m.MethodCall: Appending sig: ua(yv) data: [2, [[1, [o, /org/freedesktop/DBus]], [6, [s, org.freedesktop.DBus]], [2, [s, org.freedesktop.DBus]], [3, [s, RequestName]], [8, [g, su]]]]
13:18:05,487 DEBUG [main] o.f.d.m.MethodCall: Appending sig: su data: [at.valli.mesh, 6]
13:18:05,502 DEBUG [main] o.f.d.m.MethodCall: Appended body, type: su start: 144 end: 172 size: 28
13:18:05,502 DEBUG [main] o.f.d.m.MethodCall: marshalled size ([0, 0, 0, 28]): 000000 00 00 00 1c ...�

13:18:05,503 DEBUG [DBusConnection] o.f.d.MessageReader: => DBusSignal [clazz=null]
13:18:05,504 DEBUG [DBusConnection] o.f.d.c.i.DBusConnection: Handling incoming signal:
13:18:05,505 DEBUG [DBus Sender Thread-1] o.f.d.MessageWriter: <= MethodCall(0,2) { Path=>/org/freedesktop/DBus, Interface=>org.freedesktop.DBus, Member=>RequestName, Destination=>org.freedesktop.DBus, Signature=>su } { at.valli.mesh, 6 }
13:18:05,521 DEBUG [DBusConnection] o.f.d.MessageReader: => DBusSignal [clazz=null]
13:18:05,521 DEBUG [DBusConnection] o.f.d.c.i.DBusConnection: Handling incoming signal:
13:18:05,522 DEBUG [DBus Worker Thread-1] o.f.d.m.DBusSignal: Converting signal to type: class org.freedesktop.DBus$NameAcquired
13:18:05,522 DEBUG [DBus Worker Thread-1] o.f.d.m.DBusSignal: Creating signal of type class org.freedesktop.DBus$NameAcquired with parameters [/org/freedesktop/DBus, :1.73]
13:18:05,523 DEBUG [DBus Worker Thread-1] o.f.DBus$NameAcquired: Creating message with serial 3
13:18:05,523 DEBUG [DBus Worker Thread-1] o.f.DBus$NameAcquired: Appending sig: yyyy data: [66, 4, 0, 1]
13:18:05,533 DEBUG [DBus Worker Thread-1] o.f.DBus$NameAcquired: Appending sig: ua(yv) data: [4, [[1, [o, /org/freedesktop/DBus]], [2, [s, org.freedesktop.DBus]], [3, [s, NameAcquired]], [8, [g, s]]]]
13:18:05,532 DEBUG [DBus Worker Thread-2] o.f.d.m.DBusSignal: Converting signal to type: class org.freedesktop.DBus$NameAcquired
13:18:05,533 DEBUG [DBus Worker Thread-2] o.f.d.m.DBusSignal: Creating signal of type class org.freedesktop.DBus$NameAcquired with parameters [/org/freedesktop/DBus, at.valli.mesh]
13:18:05,534 DEBUG [DBus Worker Thread-2] o.f.DBus$NameAcquired: Creating message with serial 4
13:18:05,534 DEBUG [DBus Worker Thread-2] o.f.DBus$NameAcquired: Appending sig: yyyy data: [66, 4, 0, 1]
13:18:05,534 DEBUG [DBus Worker Thread-2] o.f.DBus$NameAcquired: Appending sig: ua(yv) data: [5, [[1, [o, /org/freedesktop/DBus]], [2, [s, org.freedesktop.DBus]], [3, [s, NameAcquired]], [8, [g, s]]]]
13:18:05,532 DEBUG [DBusConnection] o.f.d.MessageReader: => MethodReturn(1,4) { Reply Serial=>2, Destination=>:1.73, Sender=>org.freedesktop.DBus, Signature=>u } { 1 }
13:18:05,536 DEBUG [DBusConnection] o.f.d.c.i.DBusConnection: Handling incoming method return: MethodReturn(1,4) { Reply Serial=>2, Destination=>:1.73, Sender=>org.freedesktop.DBus, Signature=>u } { 1 }
13:18:05,544 DEBUG [main] o.f.d.m.ObjectTree: Adding /at/valli/mesh to object tree
13:18:05,568 DEBUG [main] o.f.d.m.ObjectTree: Adding /at/valli/mesh/element/0 to object tree
13:18:05,570 DEBUG [main] o.f.d.m.ObjectTree: Adding /at/valli/mesh/element/1 to object tree
13:18:05,603 DEBUG [main] o.f.d.m.MethodCall: Creating message with serial 5
13:18:05,604 DEBUG [main] o.f.d.m.MethodCall: Appending sig: yyyy data: [66, 1, 0, 1]
13:18:05,612 DEBUG [main] o.f.d.m.MethodCall: Appending arguments with signature: oay
13:18:05,612 DEBUG [main] o.f.d.m.MethodCall: Appending sig: ua(yv) data: [5, [[1, [o, /org/bluez/mesh]], [6, [s, org.bluez.mesh]], [2, [s, org.bluez.mesh.Network1]], [3, [s, Join]], [8, [g, oay]]]]
13:18:05,614 DEBUG [main] o.f.d.m.MethodCall: Appending sig: oay data: [/at/valli/mesh, [13, -20, -21, -22, -10, 34, 73, 5, -82, -109, -6, 38, 24, -42, -80, -121]]
13:18:05,614 DEBUG [main] o.f.d.m.MethodCall: Appended body, type: oay start: 128 end: 172 size: 44
13:18:05,620 DEBUG [main] o.f.d.m.MethodCall: marshalled size ([0, 0, 0, 44]): 000000 00 00 00 2c ...,

13:18:05,621 DEBUG [DBus Sender Thread-1] o.f.d.MessageWriter: <= MethodCall(0,5) { Path=>/org/bluez/mesh, Interface=>org.bluez.mesh.Network1, Member=>Join, Destination=>org.bluez.mesh, Signature=>oay } { /at/valli/mesh, [13, -20, -21, -22, -10, 34, 73, 5, -82, -109, -6, 38, 24, -42, -80, -121] }
13:18:25,624 DEBUG [main] o.f.d.c.i.DBusConnection: Disconnecting last remaining DBusConnection
13:18:25,625 DEBUG [main] o.f.d.e.Error: Creating message with serial 6
13:18:25,628 DEBUG [main] o.f.d.e.Error: Appending sig: yyyy data: [66, 3, 0, 1]
13:18:25,629 DEBUG [main] o.f.d.e.Error: Appending sig: ua(yv) data: [6, [[4, [s, org.freedesktop.DBus.Local.Disconnected]], [5, [u, 0]], [6, [s, org.freedesktop.DBus.Local]], [8, [g, s]]]]
13:18:25,635 DEBUG [main] o.f.d.e.Error: Appending sig: s data: [Disconnected]
13:18:25,636 DEBUG [main] o.f.d.c.i.DBusConnection: Sending disconnected signal
13:18:25,637 DEBUG [main] o.f.d.i.Local$Disconnected: Creating message with serial 7
13:18:25,641 DEBUG [main] o.f.d.i.Local$Disconnected: Appending sig: yyyy data: [66, 4, 0, 1]
13:18:25,642 DEBUG [main] o.f.d.i.Local$Disconnected: Appending sig: ua(yv) data: [8, [[1, [o, /]], [2, [s, org.freedesktop.DBus.Local]], [3, [s, Disconnected]]]]
13:18:25,643 DEBUG [main] o.f.d.c.i.DBusConnection: Handling incoming signal:
13:18:25,645 DEBUG [main] o.f.d.c.i.DBusConnection: Handling Disconnected signal from bus
13:18:25,646 DEBUG [main] o.f.d.e.Error: Creating message with serial 8
13:18:25,646 DEBUG [main] o.f.d.e.Error: Appending sig: yyyy data: [66, 3, 0, 1]
13:18:25,647 DEBUG [main] o.f.d.e.Error: Appending sig: ua(yv) data: [8, [[4, [s, org.freedesktop.DBus.Local.Disconnected]], [5, [u, 0]], [6, [s, org.freedesktop.DBus.Local]], [8, [g, s]]]]
13:18:25,650 DEBUG [main] o.f.d.e.Error: Appending sig: s data: [Disconnected]
13:18:25,652 DEBUG [main] o.f.d.c.i.DBusConnection: Handling Disconnected signal from bus
13:18:25,653 DEBUG [main] o.f.d.e.Error: Creating message with serial 9
13:18:25,653 DEBUG [main] o.f.d.e.Error: Appending sig: yyyy data: [66, 3, 0, 1]
13:18:25,658 DEBUG [main] o.f.d.e.Error: Appending sig: ua(yv) data: [9, [[4, [s, org.freedesktop.DBus.Local.Disconnected]], [5, [u, 0]], [6, [s, org.freedesktop.DBus.Local]], [8, [g, s]]]]
13:18:25,658 DEBUG [main] o.f.d.e.Error: Appending sig: s data: [Disconnected]
13:18:25,658 DEBUG [main] o.f.d.c.i.DBusConnection: Disconnecting Abstract Connection
13:18:25,659 DEBUG [main] o.f.d.c.Transport: Disconnecting Transport
13:18:25,659 DEBUG [main] c.a.m.u.UnixSocket: Closing socket
13:18:25,672 DEBUG [main] o.f.d.MessageWriter: Closing Message Writer
org.freedesktop.dbus.errors.NoReply: No reply within specified time
at org.freedesktop.dbus.RemoteInvocationHandler.executeRemoteMethod(RemoteInvocationHandler.java:160)
at org.freedesktop.dbus.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:228)
at com.sun.proxy.$Proxy19.Join(Unknown Source)
at at.valli.Main.main(Main.java:34)
13:18:25,672 DEBUG [main] c.a.m.u.UnixSocket: Closing socket`

The method I want to invoked is defined as follows:
void Join(object app_defined_root, array{byte}[16] uuid)

<method name="Join"> <arg name="app" type="o" direction="in"/> <arg name="uuid" type="ay" direction="in"/> </method>

I've mapped that with the help of the CodeGenerator to:
void Join(DBusInterface app_defined_root, List<Byte> uuid);

Best regards
valli

Unexporting object does not remove from introspection

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.

Refactor DBusDaemon to start embedded

I'd like to do minimal possible refactoring to start the DBusDaemon embedded (e.g. for tests). Currently its only possible to do that with some reflection hacking.
What do you think?

Failed to construct outgoing method call: Primative array being sent as non-primative array.

I'm happy to see the original dbus-java library being continued in this library and seeing active development on it. Can you give me your thoughts on the following:

I sometimes get an exception like this one, when doing a method call from Java to a C application:
"org.freedesktop.dbus.exceptions.DBusExecutionException: Failed to construct outgoing method call: Primative array being sent as non-primative array."
The method I invoke, looks like this: "int frameTransmit(byte[] frame);"
I'm a bit puzzled because this only happens ocassionally, not consistently. I'm starting to suspect some kind of multi-threading issues perhaps.

The exception message appears to originate in Message.java#683. As I understand this happens before invoking the remote method, when the signature of an array argument to the method to be called is checked. Apparently it cannot find a specifier for a primitive type in this signature.

Could this indeed be some kind of multi-threading race condition?
In a future version, can you perhaps update the exception message to include the offending type specifier in the signature? Also perhaps update the spelling of the word primitive?

InterfaceCodeGenerator incorrectly maps advanced types

InterfaceCodeGenerator (3.0.2) creates invalid interfaces

Mappings for advanced data types: i.e. a{sv} gets mapped as Map<CharSequence> which is not valid for a Map as it requres two type identifiers.

This is what I get from org.freedesktop.UDisks2 /org/freedesktop/UDisks2

package org.freedesktop.dbus;

import org.freedesktop.dbus.types.Variant;
import java.util.Map;
import java.util.List;
import org.freedesktop.dbus.messages.DBusSignal;

/**
 * Auto-generated class.
 */
public interface Properties {


    public Variant Get(String interface_name, String property_name);
    public Map<String> GetAll(String interface_name);
    public void Set(String interface_name, String property_name, Variant value);


    public static class PropertiesChanged extends DBusSignal {

        private final String interface_name;
        private final Map<String> changed_properties;
        private final List<String> invalidated_properties;


        public String getInterface_name() {
            return interface_name;
        }

        public Map<String> getChanged_properties() {
            return changed_properties;
        }

        public List<String> getInvalidated_properties() {
            return invalidated_properties;
        }


    }
}

Oh, and by the way, aren't those private final fields to be initialized (by a constructor)?

private static String getTypeAdv(String _dbusType, Set<String> _javaIncludes) throws DBusException {

Sending structure as a parameter of a signal

Hello,

When I try to send my custom structure, that extends Structure from your library, and send it as a parameter of my custom signal, extended from DBusSignal, I always get EOF error.

I think that there is some problem with parameter sig in the constructor of DBusSignal,
when I pass "r", "(" or "(r)" I get EOF exception, and when I pass ")" nothing happens, a message is not added to the queue for sending at all.

Code Generation Creates Duplicate Conflicting Structn Files for firewalld

Running the DBus Java code generation, henceforth referred to as CreateInterface, to generate code for the firewalld DBus interfaces creates a main API class and a number of supporting classes, in particular Struct?.java, which are used to pass data over the method calls between the client and the firewalld DBus service. The firewalld DBus interface name is ' org.fedoraproject.FirewallD1' and it exposes several objects using this interface. For the purposes of this disucssion, the ones I am interested in are:

  • /org/fedoraproject/FirewallD1
  • /org/fedoraproject/FirewallD1/config
  • /org/fedoraproject/FirewallD1/config/service/0/
  • /org/fedoraproject/FirewallD1/config/zone/0

Running CreateInterface to create code for the object path '/org/fedoraproject/FirewallD1/config` creates 16 Struct?.java files in the package org.fedoraproject.FirewallD1, named Struct1.java -> Struct16.java.

Running CreateInterface to create code for the object path '/org/fedoraproject/FirewallD1/config/service/0` creates 8 Struct?.java files in the package org.fedoraproject.FirewallD1, named Struct1.java -> Struct8.java.

Running CreateInterface to create code for the object path '/org/fedoraproject/FirewallD1/config/zone/0` creates 11 Struct?.java files in the package org.fedoraproject.FirewallD1, named Struct1.java -> Struct11.java.

Unfortunately, later Structn files overwrite earlier Structn files, and they have different fields and methods, so the generated code does not compile.

E.g. the Struct1.java file for objectPath /org/fedoraproject/FirewallD1/config is:

	package org.fedoraproject.FirewallD1.config;
	import java.util.List;
	import org.freedesktop.dbus.Position;
	import org.freedesktop.dbus.Struct;
	public final class Struct1 extends Struct
	{
	   @Position(0)
	   public final List<CharSequence> a;
	   @Position(1)
	   public final List<CharSequence> b;
	   @Position(2)
	   public final List<CharSequence> c;
	   @Position(3)
	   public final List<Integer> d;
	  public Struct1(List<CharSequence> a, List<CharSequence> b, List<CharSequence> c, List<Integer> d)
	  {
	   this.a = a;
	   this.b = b;
	   this.c = c;
	   this.d = d;
	  }
	}

And the Struct1.java file for objectPath /org/fedoraproject/FirewallD1/config/service/0 is:

	package org.fedoraproject.FirewallD1.config;
	import java.util.List;
	import java.util.Map;
	import org.freedesktop.dbus.Position;
	import org.freedesktop.dbus.Struct;
	public final class Struct1 extends Struct
	{
	   @Position(0)
	   public final CharSequence a;
	   @Position(1)
	   public final CharSequence b;
	   @Position(2)
	   public final CharSequence c;
	   @Position(3)
	   public final List<Struct7> d;
	   @Position(4)
	   public final List<CharSequence> e;
	   @Position(5)
	   public final Map<CharSequence,CharSequence> f;
	   @Position(6)
	   public final List<CharSequence> g;
	   @Position(7)
	   public final List<Struct8> h;
	  public Struct1(CharSequence a, CharSequence b, CharSequence c, List<Struct7> d, List<CharSequence> e, Map<CharSequence,CharSequence> f, List<CharSequence> g, List<Struct8> h)
	  {
	   this.a = a;
	   this.b = b;
	   this.c = c;
	   this.d = d;
	   this.e = e;
	   this.f = f;
	   this.g = g;
	   this.h = h;
	  }
	}

dynamicProxy issue with interface name overriding

Hi!

I have been using dbus-java 2.* and now experimenting with 3.0 SNAPSHOT. I ran to an issue with code that is getting a DBus object, calling DBusConnection.dynamicProxy:

org.freedesktop.dbus.exceptions.DBusExecutionException: Invalid arguments
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.freedesktop.dbus.errors.Error.getException(Error.java:150)
	at org.freedesktop.dbus.errors.Error.throwException(Error.java:180)
	at org.freedesktop.dbus.RemoteInvocationHandler.executeRemoteMethod(RemoteInvocationHandler.java:163)
	at org.freedesktop.dbus.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:227)
	at com.sun.proxy.$Proxy37.Connect(Unknown Source)
[...]

Cranking up the debug levels I see:

2018-06-06 04:27:29 [DBus Worker Thread-3] DEBUG o.f.d.c.impl.DBusConnection - Trying interface org.freedesktop.DBus.Introspectable
2018-06-06 04:27:29 [DBus Worker Thread-3] DEBUG o.f.d.c.impl.DBusConnection - Trying interface org.freedesktop.DBus.Introspectable
2018-06-06 04:27:29 [DBus Worker Thread-3] DEBUG o.f.d.c.impl.DBusConnection - Trying interface net.connman.Service
2018-06-06 04:27:29 [DBus Worker Thread-3] DEBUG o.f.d.c.impl.DBusConnection - Trying interface net.connman.Service
2018-06-06 04:27:29 [DBus Worker Thread-3] DEBUG o.f.d.c.impl.DBusConnection - 
org.freedesktop.dbus.exceptions.DBusException: Could not find an interface to cast to
	at org.freedesktop.dbus.connections.impl.DBusConnection.dynamicProxy(DBusConnection.java:302)
	at org.freedesktop.dbus.connections.impl.DBusConnection.getExportedObject(DBusConnection.java:334)
	at org.freedesktop.dbus.Marshalling.deSerializeParameter(Marshalling.java:502)
	at org.freedesktop.dbus.Marshalling.deSerializeParameters(Marshalling.java:698)
	at org.freedesktop.dbus.connections.AbstractConnection$2.run(AbstractConnection.java:675)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

Digging into dynamicProxy, I see that it is getting first the object as Introspectable and checking if it can load any interfaces that it declares in the introspection XML, then just using the first one. But it does not take into account if someone has overridden the Java package / DBus interface sync with DBusInterfaceName.

I have these overrides in place in every DBus interface I access, and now in 3.0 also the DBus Introspectable Java package diverges from the DBus interface name. I guess this has previously worked because Introspectable is(?) the interface every DBus object has, and its Java package has been matching the interface name, and you can cast the proxy to another interface. But now Introspectable Java package does not match the DBus interface name any more, and the whole thing fails.

Does this make any sense? Should there be a mechanism that given ClassNotFoundEx for an introspected IF, tries to check if there is a class annotated with IF name override with matching value? Or in the case no classes matching the interfaces can be found (or actually in any case), just use Introspectable since all DBus objects should implement that?

Something along the lines of (DBusConnection.dynamicProxy:301-) ?

            if (ifcs.size() == 0) {
                //throw new DBusException("Could not find an interface to cast to");
                ifcs.add(Introspectable.class);
            }

file descriptorsto a client that doesn't support

Important part filedescriptor is not implement. You can't handle many actions, for example org.bluez.Profile1.NewConnection

/var/log/syslog
bluetoothd[306]: Serial Port replied with an error: org.freedesktop.DBus.Error.NotSupported, Tried to send message with Unix file descriptorsto a client that doesn't support that.

2.7 Branch

As one important debugging issue wasn't fixed, would you consider creating a separate 2.7 branch that would be at the 2.7.5 tag? Then I would submit a PR there so you can upload the actually fixed version.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.