Skip to content

Crash on returning list of nested objects. #163

@brett-smith

Description

@brett-smith

I'm seeing a connection crash when attempting to access an exported list of objects.

I have distilled the problem from my application into a short, self contained example.

You'll see that getPartNames() works (a list of strings), but getParts() fails (a list of actual objects). As I understand it, dbus-java should turn these into ObjectPath native types for you. This does appear to happen, as if I look in d-feet I can see the method signature correctly, but actually calling it results in the connection being terminated.

It didn't seem to matter if I exported the "parts" myself, the result was the same.

Am I doing it wrong or is this a bug?

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.freedesktop.dbus.annotations.DBusInterfaceName;
import org.freedesktop.dbus.connections.impl.DBusConnection;
import org.freedesktop.dbus.connections.impl.DBusConnectionBuilder;
import org.freedesktop.dbus.interfaces.DBusInterface;

public class ExportNested {
	public static void main(String[] args) throws Exception {
		try (DBusConnection conn = DBusConnectionBuilder.forSessionBus().build()) {
			var part1 = new MyObjectPart();
			part1.setVal1("ABC");
			part1.setVal2("123");

			var part2 = new MyObjectPart();
			part2.setVal1("DEF");
			part2.setVal2("456");
			
			var myIface = new MyObject();
			myIface.getParts().addAll(Arrays.asList(part1, part2));
			
			conn.requestBusName("com.acme");
			conn.exportObject(part1);
			conn.exportObject(part2);
			conn.exportObject(myIface);
			
			try (DBusConnection innerConn = DBusConnectionBuilder.forSessionBus().build()) {
				var myObject = innerConn.getRemoteObject("com.acme", "/com/acme/MyObject", MyInterface.class);
				
				// Works
				System.out.println("> " + myObject.sayHello());
				
				// Works
				for(String part : myObject.getPartNames()) {
					System.out.println("  " + part);
				}
				
				// Fails
				for(MyInterfacePart part : myObject.getParts()) {
					System.out.println("  " + part.getObjectPath() + " = " +  part.getVal1() + " / " + part.getVal2());
				}
			}
		}
	}
	
	@DBusInterfaceName("com.acme.MyInterface")
	public interface MyInterface extends DBusInterface {
		
		String sayHello();
		
		List<MyInterfacePart> getParts();
		
		List<String> getPartNames();
	}
	
	public static class MyObject implements MyInterface {
		
		private List<MyInterfacePart> parts = new ArrayList<>();
		
		public String sayHello() {
			return "Hello!";
		}
		
		public List<MyInterfacePart> getParts() {
			return parts;
		}

	    public String getObjectPath() {
	    	return "/com/acme/MyObject";
	    }

		@Override
		public List<String> getPartNames() {
			return parts.stream().map(i -> i.getVal1()).collect(Collectors.toList());
		}
	}

	@DBusInterfaceName("com.acme.MyInterfacePart")
	public interface MyInterfacePart extends DBusInterface {
		
		String getVal1();

		String getVal2();
	}

	public static class MyObjectPart implements MyInterfacePart {
		
		private String val1;
		private String val2;
		
		public String getVal1() {
			return val1;
		}

		public void setVal1(String val1) {
			this.val1 = val1;
		}

		public String getVal2() {
			return val2;
		}

		public void setVal2(String val2) {
			this.val2 = val2;
		}

	    public String getObjectPath() {
	    	return "/com/acme/MyPart" + val1;
	    }
	}

This results in ..

> Hello!
  ABC
  DEF
16:15:25.657 [DBusConnection [listener=false]] ERROR o.f.d.c.IncomingMessageThread - FatalException in connection thread
org.freedesktop.dbus.exceptions.FatalDBusException: java.io.EOFException: Underlying transport returned EOF (1)
	at org.freedesktop.dbus.connections.AbstractConnection.readIncoming(AbstractConnection.java:1085)
	at org.freedesktop.dbus.connections.IncomingMessageThread.run(IncomingMessageThread.java:41)
Caused by: java.io.EOFException: Underlying transport returned EOF (1)
	at org.freedesktop.dbus.spi.message.InputStreamMessageReader.readMessage(InputStreamMessageReader.java:52)
	at org.freedesktop.dbus.connections.transports.AbstractTransport.readMessage(AbstractTransport.java:85)
	at org.freedesktop.dbus.connections.AbstractConnection.readIncoming(AbstractConnection.java:1074)
	... 1 common frames omitted

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions