fluxroot / jcpi

A Java Chess Protocol Interface
https://github.com/fluxroot/jcpi
Apache License 2.0
23 stars 8 forks source link

UnsupportedOperationException when trying to remove empty tokens in UciProtocol.java, method signature: private List<String> getTokens(String s) #102

Closed cjbolt closed 9 years ago

cjbolt commented 9 years ago

Hi,

Thanks ever so much for jcpi. It got me started writing my first chess engine, EubosChess. I have really enjoyed doing this, and I probably wouldn't have got started without your well designed UCI lib code.

However, I have a bug to report. I'm using maven to get version 1.4.0. I have used it with Arena on a Windows 7 PC without ever encountering an issue. However I am now porting to Android (using Chess for Android as a GUI) and have run into an issue on the Android Dalvik VM build. Chess for Android sends the following string "position startpos moves a2a3 e7e5 b2b4". There are double spaces between the moves. This causes a crash when it tries to remove the 0 length string tokens "" at line 502; iter.remove();

04-30 20:28:40.644 5922-6087/cjbolt.github.com.eubosforandroid2 E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-598 Process: cjbolt.github.com.eubosforandroid2, PID: 5922 java.lang.UnsupportedOperationException at java.util.AbstractList.remove(AbstractList.java:638) at java.util.AbstractList$SimpleListIterator.remove(AbstractList.java:75) at com.fluxchess.jcpi.protocols.UciProtocol.getTokens(UciProtocol.java:502) at com.fluxchess.jcpi.protocols.UciProtocol.parsePositionCommand(UciProtocol.java:188) at com.fluxchess.jcpi.protocols.UciProtocol.receive(UciProtocol.java:83) at com.fluxchess.jcpi.protocols.IOProtocolHandler.receive(IOProtocolHandler.java:56) at com.fluxchess.jcpi.AbstractEngine.run(AbstractEngine.java:58) at java.lang.Thread.run(Thread.java:818)

I wondered if you have any idea whats going wrong - I'm a relative novice with Java - in the mean time I will make a unit test on Windows environment to see if I can reproduce the exception on the standard JVM version.

Cheers and thanks again, Chris

cjbolt commented 9 years ago

Confirmed, this is also a problem in Windows with JavaSE-1.8.

fluxroot commented 9 years ago

Hey Chris! Nice catch! The problem is that Arrays.asList() passes the remove() request to the array which is not supported of course. The solution is to create a new array list from the array.

fluxroot commented 9 years ago

Oh well, thanks for the compliments! Glad to hear that you enjoyed using JCPI. You're doing really good with EubosChess! If you have any questions about JCPI or chess engine development, just drop me a mail. I could probably give you some advanced pointers. :+1: