Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing to read XAuthority file on Ubuntu 22.04 #42

Open
nhrdl opened this issue Dec 24, 2024 · 3 comments
Open

Failing to read XAuthority file on Ubuntu 22.04 #42

nhrdl opened this issue Dec 24, 2024 · 3 comments

Comments

@nhrdl
Copy link

nhrdl commented Dec 24, 2024

I tried the default hello world example and it fails to read the XAuthority file on Ubuntu 22.04. Following code snippet seems to be working in reading the file and it does show window. Following code is based on https://stackoverflow.com/a/74840795

    public static Optional<XAuthority> read(DataInput in) {
        try {
            int family = in.readUnsignedShort();
            int addLength = in.readUnsignedShort();
            List<Byte> host = readBytes(in, addLength);
            int displayNoLength = in.readUnsignedShort(), displayNumber = 0;

            if (displayNoLength != 0) {
                List<Byte> displayNo = readBytes(in, displayNoLength);
            }
            int nameLength = in.readUnsignedShort();
            List<Byte> authName = readBytes(in, nameLength);
            int dataLength = in.readUnsignedShort();
            List<Byte> authData = readBytes(in, dataLength);
            XAuthority auth = new XAuthority(Family.getByCode(family), host, displayNumber, authName, authData);
            return Optional.of(auth);

        } catch (Exception e) {
            // TODO Auto-generated catch block
            throw new RuntimeException(e);
        }
    }

Since XClient constructor was private, I ended up using reflection to call the constructor using something like following

X11Connection connect = X11Connection.connect(false, new DisplayName(":1"), auth);
Constructor<X11Client> accessibleConstructor = ReflectionUtils.accessibleConstructor(X11Client.class,
        X11Connection.class);
try (X11Client x11Client = accessibleConstructor.newInstance(connect)) { ....
@moaxcp
Copy link
Owner

moaxcp commented Dec 25, 2024

Is this with version 0.19.0? It could be due to the little endian changes and the file being big endian.

@nhrdl
Copy link
Author

nhrdl commented Dec 26, 2024

Yes, version 0.19.0.

I tried with enedian settings both true and false. Result is still same. I get folowing exception

  Exception in thread "main" java.lang.NumberFormatException: For input string: ""
	at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
	at java.base/java.lang.Integer.parseInt(Integer.java:672)
	at java.base/java.lang.Integer.parseInt(Integer.java:778)
	at com.github.moaxcp.x11.protocol.XAuthority.read(XAuthority.java:101)
	at com.github.moaxcp.x11.protocol.XAuthority.getAuthorities(XAuthority.java:161)
	at com.github.moaxcp.x11.x11client.X11Connection.connect(X11Connection.java:148)
	at com.github.moaxcp.x11.x11client.X11Client.connect(X11Client.java:74)
	at com.paymentus.bfs.aggregation.x11.X11Driver.main(X11Driver.java:202)

@moaxcp
Copy link
Owner

moaxcp commented Dec 27, 2024

I release 0.20.0 with a fix that should help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants