faljse / SDNotify

SDNotify implements the systemd notification protocol in Java.
GNU Lesser General Public License v2.1
58 stars 18 forks source link

Project should run with JDK 1.8 but uses a method from JDK 9 #13

Open gerolfscherr opened 5 months ago

gerolfscherr commented 5 months ago

The Project is supposed to run with jdk 1.8 but it uses a method which is marked @since 9 and therefore doesn't really work on jdk 1.8, see Stacktrace below:

        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
Exception in thread "main" java.lang.NoSuchMethodError: java.util.List.of(Ljava/lang/Object;Ljava/lang/Object;)Ljava/util/List;
  at info.faljse.SDNotify.jna.CLibrary$SockAddr.getFieldOrder(CLibrary.java:81)
  at com.sun.jna.Structure.fieldOrder(Structure.java:1044)
  at com.sun.jna.Structure.getFields(Structure.java:1098)
  at com.sun.jna.Structure.deriveLayout(Structure.java:1265)
  at com.sun.jna.Structure.calculateSize(Structure.java:1192)
  at com.sun.jna.Structure.calculateSize(Structure.java:1144)
  at com.sun.jna.Structure.allocateMemory(Structure.java:426)
  at com.sun.jna.Structure.<init>(Structure.java:216)
  at com.sun.jna.Structure.<init>(Structure.java:204)
  at com.sun.jna.Structure.<init>(Structure.java:191)
  at com.sun.jna.Structure.<init>(Structure.java:183)
  at info.faljse.SDNotify.jna.CLibrary$SockAddr.<init>(CLibrary.java:75)
  at info.faljse.SDNotify.SDNotify.<init>(SDNotify.java:48)
  at info.faljse.SDNotify.SDNotify.getInstance(SDNotify.java:186)
  at info.faljse.SDNotify.SDNotify.sendNotify(SDNotify.java:72)
gerolfscherr commented 5 months ago

the offending line is: https://github.com/faljse/SDNotify/blob/fa5f368c06b7ea62e2924b676bf449e2b3ed14c7/src/main/java/info/faljse/SDNotify/jna/CLibrary.java#L81 and the fix would be something like

        @Override
        protected List<String> getFieldOrder() {
            ArrayList a = new ArrayList();
            a.add("family");
            a.add("addr");
            return Collections.unmodifiableList(a);
        }