0

I am trying to use a chess PGN parsing library to parse a PGN file and simply create a text file.

  1. The lib: https://github.com/bhlangonijr/chesslib

  2. My maven project: https://github.com/divukman/chess_pgn_text/tree/master/pgntotext


Problem:

  1. I can run it in IntelliJ (just run the main class) and it works.

  2. If I create a fat jar (mvn package) and run it with java -jar target/pgn-to-text-1.0-SNAPSHOT.jar I get following error:

  Exception in thread "main" com.github.bhlangonijr.chesslib.pgn.PgnException: Error parsing PGN[1, ]:
        at com.github.bhlangonijr.chesslib.pgn.PgnHolder.loadPgn(PgnHolder.java:343)
        at chess.Main.main(Main.java:18)
Caused by: java.lang.NullPointerException
        at com.github.bhlangonijr.chesslib.pgn.PgnHolder.loadPgn(PgnHolder.java:206)
        ... 1 more

Any idea why it would work when running from the IDE and not when running from the jar? Why would it fail with null pointer exception? As if it did not read the file correctly!?!

Dimitar Vukman
  • 421
  • 6
  • 15
  • 1
    Are you parsing any file ? Probably the file is not located. – Sambit Jul 27 '19 at 20:13
  • 1
    Seems like event is null. This may be becouse the map events does not contain p.value() (PgnHolder:173) – dan1st Jul 27 '19 at 20:35
  • Hi guys. Thank you all for the answers. Path of the file used is hard coded and exists on the drive, that's what got me wondering. As if it does not read it correctly when run from the jar. My reasoning goes with all you said here. I will continue investigating, use different files, package them within jar :) etc... Will update the post once resolved. – Dimitar Vukman Jul 28 '19 at 07:31

2 Answers2

1

Looks like PgnProperty p is null at this line which can be null if your input data is not in correct format here. Probably you are using different files in IntelliJ and fatjar which is causing the issue.

Abhishek Garg
  • 2,158
  • 1
  • 16
  • 30
  • Something very weird is going on here. Seems like it has something to do with the way I create the PGN file. I use ChessBase app to convert their own DB format to PGN. Content of the file is FINE! However, the file itself is not!?! I took random PGN online, app works fine when run from jar! Then I took the content from that file and pasted into my PGN, thinking the format is off... guess what, same error, good content. However, when I run it from inside intelliJ, it reads it fine. So, something happens to the file itslef that is causing it not to be read when running from the .jar... – Dimitar Vukman Jul 28 '19 at 07:54
0

I did some comparing between what works and what does not. The file I produced had UTF-8 encoding, which, apparently does not work when run from the jar file.

When I edited the file and saved it as ANSI, it works fine! So, I am marking this mystery as done and I need to see what to set up so it will read utf8 files when running from the jar.

Dimitar Vukman
  • 421
  • 6
  • 15