Unable to create HashTable with org.gnome.secret.SchemaAttributeType as value #297

Closed
opened 2025-11-09 11:21:14 +01:00 by Nyeksenn · 2 comments
Nyeksenn commented 2025-11-09 11:21:14 +01:00 (Migrated from github.com)

If I want to create a schema using the libsecret bindings the following has to be done:

var table = new HashTable<>(GLib::strHash, GLib::strEqual,
        (address) -> address.getString(0),
        (address) -> SchemaAttributeType.of(address.getAtIndex(ValueLayout.JAVA_INT, 0)));
table.insert("user", SchemaAttributeType.STRING);
var schema = new Schema("MySchema", SchemaFlags.NONE, table);

However, this is currently not possible because inserting into the table fails with an assertion error:

Exception in thread "main" java.lang.AssertionError: java.lang.IllegalArgumentException: Not a MemorySegment, String, primitive or Proxy
	at org.gnome.glib.HashTable.insert(HashTable.java:570)
	at io.github.Nyeksenn.grooveboat.Main.main(Main.java:54)
Caused by: java.lang.IllegalArgumentException: Not a MemorySegment, String, primitive or Proxy
Caused by: java.lang.IllegalArgumentException: Not a MemorySegment, String, primitive or Proxy

	at org.javagi.interop.Interop.getAddress(Interop.java:626)
	at org.gnome.glib.HashTable.insert(HashTable.java:568)
	... 1 more

Java-GI version: 0.13.0-RC1

If I want to create a schema using the libsecret bindings the following has to be done: ```java var table = new HashTable<>(GLib::strHash, GLib::strEqual, (address) -> address.getString(0), (address) -> SchemaAttributeType.of(address.getAtIndex(ValueLayout.JAVA_INT, 0))); table.insert("user", SchemaAttributeType.STRING); var schema = new Schema("MySchema", SchemaFlags.NONE, table); ``` However, this is currently not possible because inserting into the table fails with an assertion error: ```bash Exception in thread "main" java.lang.AssertionError: java.lang.IllegalArgumentException: Not a MemorySegment, String, primitive or Proxy at org.gnome.glib.HashTable.insert(HashTable.java:570) at io.github.Nyeksenn.grooveboat.Main.main(Main.java:54) Caused by: java.lang.IllegalArgumentException: Not a MemorySegment, String, primitive or Proxy Caused by: java.lang.IllegalArgumentException: Not a MemorySegment, String, primitive or Proxy at org.javagi.interop.Interop.getAddress(Interop.java:626) at org.gnome.glib.HashTable.insert(HashTable.java:568) ... 1 more ``` Java-GI version: 0.13.0-RC1
jwharm commented 2025-11-10 19:25:53 +01:00 (Migrated from github.com)

Last weekend I started experimenting a bit, and added support for enum values in hashtables in the enum-hashtable branch. I'm not completely satisfied with it though.

Last weekend I started experimenting a bit, and added support for enum values in hashtables in the [enum-hashtable](https://github.com/jwharm/java-gi/tree/enum-hashtable) branch. I'm not completely satisfied with it though.
jwharm commented 2025-11-10 19:37:29 +01:00 (Migrated from github.com)

The reason I'm not satisfied with it yet, is that the solution in the new branch adds a static of(MemorySegment) function in all enum/flags classes. I'd rather read the enum value from memory somewhere else and simply call the existing of(int) functions, but that doesn't play well with the HashTable constructor...

Tangentially related: all flags classes have of(int) functions, just like the enumeration classes, but on second thought, I think those should actually return a Set<FooFlags> instead of a single FooFlags value. For example: ApplicationFlags.of(int)) would error out when the input value is NON_UNIQUE | HANDLES_COMMAND_LINE.

The reason I'm not satisfied with it yet, is that the solution in the new branch adds a static `of(MemorySegment)` function in all enum/flags classes. I'd rather read the enum value from memory somewhere else and simply call the existing `of(int)` functions, but that doesn't play well with the HashTable constructor... Tangentially related: all flags classes have `of(int)` functions, just like the enumeration classes, but on second thought, I think those should actually return a `Set<FooFlags>` instead of a single `FooFlags` value. For example: [ApplicationFlags.of(int)](https://java-gi.org/javadoc/org/gnome/gio/ApplicationFlags.html#of(int))) would error out when the input value is `NON_UNIQUE | HANDLES_COMMAND_LINE`.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
java-gi/java-gi#297
No description provided.