Repository navigation
Removing check for writable file - #650
viniciusccarvalho wants to merge 1 commit into
Conversation
Seems that file.isWritable() is unreliable depending on the OS/JDK version. The catch clause of the block would capture if the file is really not writable anyways.
|
Hi, do you think this is the source of the problem for the motor part? |
|
It solved the problem here. The fact that an exception will be thrown anyways, and where most of the times the file should be writable, the check is redundant. There are a few reports of canXXXX methods being broken on JDK depending on the version/OS Read here: https://stackoverflow.com/questions/10783677/how-to-check-file-permissions-in-java-os-independently And here: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6203387 |
|
Hi, I believe that this is not the cause of the motor issue. But the permission check probably is redundant as the exception is going to be caught and printed out by the catch block below it.
I think this problem are caused by having a race condition with According to the following part of this comment...
...something is triggering a change in In some places there is a workaround: a fixed delay which should cover most of the cases. If the hypothesis about the udev race-condition is correct, the proper solution to this is to wait until udev realizes that there is a new device and it applies its rules. Yesterday I tried implementing a sensor/motor "backend" via udev-java-bindings and it seems viable, However (and I hope it is only due to JNA) the startup performance quite suffered. The next step is to reimplement it via JNI. However I do not want to promise anything. Regards, Jakub |
|
@JakubVanek the "mount" change was not happening due motors being reconnected, that's what lead me to make this comment. I would assume that a change in the port mapping to be normal on reconnect, but I have observed that during redeployment of my app, the motors would change ports. Your suspicion on race condition, I have also noticed that this error happens as part of the constructor of the Would make sense to move the Perhaps turning the reset in to a Maybe that can also reduce the chances of racing conditions |
|
Please @viniciusccarvalho create an issue to continue this technical conversation. @JakubVanek, we spoke about udev, previously. It is not necessary. |
|
We will continue the discussion in the issue. |
|
Hmm, if I look at this from a theoretical point of view, it is be better to check the failure with exception type. That will make it a bit more atomic, i.e. opening and checking the permission should happen in one step in the |
This commit makes some refactorings in Sysfs: - #650 is integrated. Together with this, the writeString() now manually encodes the string to bytes and writes it using FileOutputStream. This should ensure the best performance. - readString() is a bit tweaked to use exceptions in a better way. - getElements() is checking for null value of a result. - write* method do not return a boolean anymore. This is because I think exceptions already convey that an error occured. The only usage of this boolean was to throw an exception. - Slf4j formatting functions are used, so it is not necessary to check if tracing is enabled. Slf4j already checks if the level is enabled before the format is processed.
|
I have built another PR on top of this one in #652 - it includes some more Sysfs refactoring. |
- Slf4j checks for log level are removed and formatting log function overloads are used. This way Slf4j does the checking on its own. - change writeString() to use FileOutputStream and better exception handling. This could also make it a little bit more faster. This also integrates #650. - change writeInteger() to use Integer.toString(). - change readString to use better exception handling. - change getElements() to check for null return value.
- Slf4j checks for log level are removed and formatting log function overloads are used. This way Slf4j does the checking on its own. - change writeString() to use FileOutputStream and better exception handling. This could also make it a little bit more faster. This also integrates #650. This avoids the use of File.isWritable() function, instead an exception will be catched and logged. - change writeInteger() to use Integer.toString(). - change readString to use better exception handling. - change getElements() to check for null return value. Co-authored-by: Vinicius Carvalho <viniciusccarvalho@gmail.com>
- Slf4j checks for log level are removed and formatting log function overloads are used. This way Slf4j does the checking on its own. - change writeString() to use FileOutputStream and better exception handling. This could also make it a little bit more faster. This also integrates #650. This avoids the use of File.isWritable() function, instead an exception will be catched and logged. - change writeInteger() to use Integer.toString(). - change readString to use better exception handling. - change getElements() to check for null return value. Co-authored-by: Vinicius Carvalho <viniciusccarvalho@gmail.com>
- Slf4j checks for log level are removed and formatting log function overloads are used. This way Slf4j does the checking on its own. - change writeString() to use FileOutputStream and better exception handling. This could also make it a little bit more faster. This also integrates #650. This avoids the use of File.isWritable() function, instead an exception will be catched and logged. - change writeInteger() to use Integer.toString(). - change readString to use better exception handling. - change getElements() to check for null return value. Co-authored-by: Vinicius Carvalho <viniciusccarvalho@gmail.com>
- Slf4j checks for log level are removed and formatting log function overloads are used. This way Slf4j does the checking on its own. - change writeString() to use FileOutputStream and better exception handling. This could also make it a little bit more faster. This also integrates #650. This avoids the use of File.isWritable() function, instead an exception will be catched and logged. - change writeInteger() to use Integer.toString(). - change readString to use better exception handling. - change getElements() to check for null return value. Co-authored-by: Vinicius Carvalho <viniciusccarvalho@gmail.com>
- Slf4j checks for log level are removed and formatting log function overloads are used. This way Slf4j does the checking on its own. - Changes to writeString() and readString() to use lower-level IO This could make it a little faster. - better exception handling - inspired by #650 - change writeInteger() to use Integer.toString(). - change getElements() to check for null return value.
- Slf4j checks for log level are removed and formatting log function overloads are used. This way Slf4j does the checking on its own. - Changes to writeString() to use lower-level IO This could make it a little faster. - better exception handling - inspired by #650 - change writeInteger() to use Integer.toString(). - change getElements() to check for null return value.
- Slf4j checks for log level are removed and formatting log function overloads are used. This way Slf4j does the checking on its own. - Changes to writeString() to use lower-level IO This could make it a little faster. - better exception handling - inspired by #650 - change writeInteger() to use Integer.toString(). - change getElements() to check for null return value.
|
This PR is mostly a refactoring - it prevents a double checking of file permissions. (actually, python has a nice name for this: To verify that it still works, try to create a To check the thrown permission-denied-exception, remove the delays in |
|
However it seems that #654 reworks this. |
|
We are not continue with this PR. |
Seems that file.isWritable() is unreliable depending on the OS/JDK version.
The catch clause of the block would capture if the file is really not writable anyways.
#651