NeuronRobotics / nrjavaserial

A Java Serial Port system. This is a fork of the RXTX project that uses in jar loading of the native code.
Other
344 stars 142 forks source link

First call CommPortIdentifier.getPortIdentifiers() ,This can lead to repeated calls #223

Closed you227 closed 2 years ago

you227 commented 2 years ago

First call CommPortIdentifier.getPortIdentifiers() ,This can lead to repeated calls,because CommPortIdentifier.java static block It will also be called once CommPortIdentifier.getPortIdentifiers(). I think the this.testNativeCode(); in the NativeResource.java inJarLoad(String name) method should be deleted.

image image image

CommPortIdentifier.java

static {
        try {
            CommDriver RXTXDriver = (CommDriver)Class.forName("gnu.io.RXTXCommDriver").newInstance();
            RXTXDriver.initialize();
        } catch (Throwable var1) {
            System.err.println(var1 + " thrown while loading gnu.io.RXTXCommDriver");
        }

        String OS = System.getProperty("os.name");
        if (OS.toLowerCase().indexOf("linux") == -1) {
        }

        SerialManager.getInstance();
    }

..... NativeResource.java

private void inJarLoad(String name) throws UnsatisfiedLinkError, NativeResourceException {
        InputStream resourceSource = this.locateResource(name);
        File resourceLocation = this.prepResourceLocation(name);

        try {
            this.copyResource(resourceSource, resourceLocation);
        } catch (IOException var5) {
            throw new UnsatisfiedLinkError();
        }

        this.loadResource(resourceLocation);
        this.testNativeCode();
    }

private void testNativeCode() throws UnsatisfiedLinkError {
        CommPortIdentifier.getPortIdentifiers();
    }
MrDOS commented 2 years ago

Duplicate of #222.