I suspect it is timing related, the code to handle initialization and mode change is horrible (it is based on the original LEGO code) and is a little non-deterministic. The LEGO code gets away with it because the VM is constantly polling the sensor and hides small glitches. Our code does not do this we only talk to the sensor when asked to do so. As a result we do all of the initialization when you open the device, but this can take a long time (the LEGO code hides this time from the user by in effect always trying to open the device after it has been attached). It may be that for some particular sensors we do not give them enough time. If I had a sensor that failed I would be adding trace code to the initialization code. As you can see from:https://sourceforge.net/p/lejos/ev3/cod ... TPort.java
there is a lot of commented out trace code already there!
As Aswin has said simply making sure the sensor is closed properly may help (as it will be in a better known state, when you next open it). It may also help to catch the exception and simply retry the operation if you do get an error. Not the best fix, but effectively what would happen if we change the port code to perform more retry operations which could well be the required fix.
If anyone is really troubled by this and has a sensor that consistently fails that they are prepared to loan me (or swap for one of mine that does not fail), then let me know. But I've not seen the issue can't easily work out what is going on.