Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13

Thread: JSONException: A JSONArray text must start with '[' at 1

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    10

    Default JSONException: A JSONArray text must start with '[' at 1

    When starting up r19417, 38 of the following occur:

    Code:
    Unexpected error, debug log printed.
    class org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]
    org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]
    	at org.json.JSONTokener.syntaxError(JSONTokener.java:423)
    	at org.json.JSONArray.<init>(JSONArray.java:113)
    	at org.json.JSONArray.<init>(JSONArray.java:157)
    	at net.sourceforge.kolmafia.persistence.ScriptManager.getJSONArray(ScriptManager.java:168)
    	at net.sourceforge.kolmafia.persistence.ScriptManager.updateRepoScripts(ScriptManager.java:151)
    	at net.sourceforge.kolmafia.persistence.ScriptManager.<clinit>(ScriptManager.java:138)
    	at net.sourceforge.kolmafia.swingui.widget.TableCellFactory.getColumnNames(TableCellFactory.java:471)
    	at net.sourceforge.kolmafia.swingui.widget.ShowDescriptionTable.<init>(ShowDescriptionTable.java:311)
    	at net.sourceforge.kolmafia.swingui.widget.ShowDescriptionTable.<init>(ShowDescriptionTable.java:170)
    	at net.sourceforge.kolmafia.swingui.panel.ItemTableManagePanel.<init>(ItemTableManagePanel.java:48)
    	at net.sourceforge.kolmafia.swingui.panel.ItemTableManagePanel.<init>(ItemTableManagePanel.java:61)
    	at net.sourceforge.kolmafia.swingui.panel.InventoryPanel.<init>(InventoryPanel.java:121)
    	at net.sourceforge.kolmafia.swingui.panel.CreateSpecialPanel.<init>(CreateSpecialPanel.java:87)
    	at net.sourceforge.kolmafia.swingui.ItemManageFrame.<init>(ItemManageFrame.java:216)
    	at net.sourceforge.kolmafia.swingui.ItemManageFrame.<init>(ItemManageFrame.java:124)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    	at java.lang.reflect.Constructor.newInstance(Unknown Source)
    	at net.sourceforge.kolmafia.CreateFrameRunnable.runConstruction(CreateFrameRunnable.java:286)
    	at net.sourceforge.kolmafia.CreateFrameRunnable.createFrame(CreateFrameRunnable.java:182)
    	at net.sourceforge.kolmafia.CreateFrameRunnable.run(CreateFrameRunnable.java:164)
    	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    	at java.awt.EventQueue.access$500(Unknown Source)
    	at java.awt.EventQueue$3.run(Unknown Source)
    	at java.awt.EventQueue$3.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)

  2. #2
    Developer fronobulax's Avatar
    Join Date
    Feb 2009
    Location
    Central Virginia, USA
    Posts
    4,430

    Default

    Hmmm..

    That happened a lot as I was moving the repository file to SourceForge and then reading, but fix was to read the file as 'raw'. That is still in place and I have not seen that since. My SVN copy of the file is also correct.

    My knee jerk reaction is to have you delete svnrepo.json in the data directory and try again. It is possible that you had a comms error and the file was not completely read or there was some file corruption and the bad version was not replaced.

    If it is still happening then maybe we need to know your operating system and what the first few characters of your svnrepo.json actually are.

  3. #3
    Senior Member
    Join Date
    Apr 2009
    Posts
    1,847

    Default

    > [character 2 line 1]

    Since in my copy the [ is character 1, maybe the file got clobbered by windows's propensity to prepend a BOM to text files?

  4. #4
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    11,999

    Default

    Interesting. I changed the way we read that JSON file to simply load the the file into a byte array and initialize a string with it.
    Works like a charm on my Mac and your Linux (if I recall correctly).

    The previous way was too ugly for words. Before:

    Code:
          BufferedReader reader = FileUtilities.getReader( repoFile );
          StringBuilder builder = new StringBuilder();
    
          try
          {
              String[] data;
              while ( ( data = FileUtilities.readData( reader ) ) != null )
              {
                  for ( String s : data )
                  {
                      builder.append( s );
                  }
              }
          }
          finally
          {
              try
              {
                  reader.close();
              }
              catch ( IOException e )
              {
                  StaticEntity.printStackTrace( e );
              }
          }
    
          try
          {
                JSONArray jArray = new JSONArray( builder.toString() );
                return jArray;
          }
    After:

    Code:
          byte[] bytes = ByteBufferUtilities.read( repoFile );
          String string = StringUtilities.getEncodedString( bytes, "UTF-8" );
    
          try
          {
                JSONArray jArray = new JSONArray( string );
                return jArray;
          }
    That technique works perfectly for loading in a raw file of HTML for "test load FILENAME", for example.
    Last edited by Veracity; 07-16-2019 at 05:25 PM.

  5. #5
    Junior Member
    Join Date
    Dec 2010
    Posts
    10

    Default

    The svnrepo.json file is empty. When I deleted it and started KoLmafia, I got the same errors and the file was recreated, again empty (0 bytes). Oh and this is in Windows 7.

  6. #6
    Developer fronobulax's Avatar
    Join Date
    Feb 2009
    Location
    Central Virginia, USA
    Posts
    4,430

    Default

    Well, I didn't write the reader code, at least.

    If the file is zero bytes then this is exactly the error one would expect when trying to read it.

    I have not had a problem on Windows 10.

    Looking at the code there is a point where if the local file exists after the remote read and has zero bytes, it is supposed to be deleted. So it is interesting that a zero byte file exists.

    Some of the IO does have debugging so maybe turn debugging on (it's on a menu on the RHS of the main screen but I can't check just now) try and load the script menu, triggering the error, and then turn off debugging and share the log?

    I have a vague recollection of some charset issues on W7 vs. W10. Maybe we are expecting a charset that is not in 7?

  7. #7
    Junior Member
    Join Date
    Dec 2010
    Posts
    10

    Default

    Umm... could you be more specific with "load the script menu"? Clicking any of "Scripts", "Refresh menu", "Load scripts...", "Script Manager" does not trigger the error.

  8. #8
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    11,999

    Default

    Since it seems to occur when creating the Item Manager frame (why in the world?), turn on debugging when you have the Login Frame showing before it logs you in and creates other frames.

  9. #9
    Junior Member
    Join Date
    Dec 2010
    Posts
    10

    Default

    Ok. So, I would expect this to be relevant:

    Code:
    Requesting: https://sourceforge.net/p/kolmafia/code/HEAD/tree/data/SVN/svnrepo.json?format=raw
    0 request properties
    
    Unexpected error, debug log printed.
    class javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    	at sun.security.ssl.Alerts.getSSLException(Unknown Source)
    	at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
    	at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
    	at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
    	at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
    	at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
    	at sun.security.ssl.Handshaker.processLoop(Unknown Source)
    	at sun.security.ssl.Handshaker.process_record(Unknown Source)
    	at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
    	at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
    	at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
    	at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
    	at sun.net.http://www.protocol.https.HttpsClien...onnect(Unknown Source)
    	at sun.net.http://www.protocol.https.AbstractDe...onnect(Unknown Source)
    	at sun.net.http://www.protocol.http.HttpURLConn...tream0(Unknown Source)
    	at sun.net.http://www.protocol.http.HttpURLConn...Stream(Unknown Source)
    	at java.net.HttpURLConnection.getResponseCode(Unknown Source)
    	at sun.net.http://www.protocol.https.HttpsURLCo...seCode(Unknown Source)
    	at net.sourceforge.kolmafia.utilities.FileUtilities.downloadFileToStream(FileUtilities.java:277)
    	at net.sourceforge.kolmafia.utilities.FileUtilities.downloadFile(FileUtilities.java:428)
    	at net.sourceforge.kolmafia.persistence.ScriptManager.updateRepoScripts(ScriptManager.java:148)
    	at net.sourceforge.kolmafia.persistence.ScriptManager.<clinit>(ScriptManager.java:138)
    	at net.sourceforge.kolmafia.swingui.widget.TableCellFactory.getColumnNames(TableCellFactory.java:471)
    	at net.sourceforge.kolmafia.swingui.widget.ShowDescriptionTable.<init>(ShowDescriptionTable.java:311)
    	at net.sourceforge.kolmafia.swingui.widget.ShowDescriptionTable.<init>(ShowDescriptionTable.java:170)
    	at net.sourceforge.kolmafia.swingui.panel.ItemTableManagePanel.<init>(ItemTableManagePanel.java:48)
    	at net.sourceforge.kolmafia.swingui.panel.ItemTableManagePanel.<init>(ItemTableManagePanel.java:61)
    	at net.sourceforge.kolmafia.swingui.panel.InventoryPanel.<init>(InventoryPanel.java:121)
    	at net.sourceforge.kolmafia.swingui.panel.CreateSpecialPanel.<init>(CreateSpecialPanel.java:87)
    	at net.sourceforge.kolmafia.swingui.ItemManageFrame.<init>(ItemManageFrame.java:216)
    	at net.sourceforge.kolmafia.swingui.ItemManageFrame.<init>(ItemManageFrame.java:124)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    	at java.lang.reflect.Constructor.newInstance(Unknown Source)
    	at net.sourceforge.kolmafia.CreateFrameRunnable.runConstruction(CreateFrameRunnable.java:286)
    	at net.sourceforge.kolmafia.CreateFrameRunnable.createFrame(CreateFrameRunnable.java:182)
    	at net.sourceforge.kolmafia.CreateFrameRunnable.run(CreateFrameRunnable.java:164)
    	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    	at java.awt.EventQueue.access$500(Unknown Source)
    	at java.awt.EventQueue$3.run(Unknown Source)
    	at java.awt.EventQueue$3.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    	at sun.security.validator.PKIXValidator.doBuild(Unknown Source)
    	at sun.security.validator.PKIXValidator.engineValidate(Unknown Source)
    	at sun.security.validator.Validator.validate(Unknown Source)
    	at sun.security.ssl.X509TrustManagerImpl.validate(Unknown Source)
    	at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source)
    	at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
    	... 48 more
    Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    	at sun.security.provider.certpath.SunCertPathBuilder.build(Unknown Source)
    	at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source)
    	at java.security.cert.CertPathBuilder.build(Unknown Source)
    	... 54 more

  10. #10
    Developer fronobulax's Avatar
    Join Date
    Feb 2009
    Location
    Central Virginia, USA
    Posts
    4,430

    Default

    Sorry for the delay.

    The original error about JSON parsing will occur if the file is created but empty.

    The second trace, with "unable to find valid certification path to requested target" indicates there was a problem trying to establish a SSL connection to SourceForge.

    I have not had to resolved one of those is a very long time and my recollection is that the solution requires Java configuration and/or importing certificates. If you can load a script using the svn command in mafia there is a chance that the problem is not just a straight forward certificate problem with SourceForge.

    My first suggestion would be to try again if only because the file has been changing rapidly and the issue might be transient. If that doesn't work we probably need to know your operating system (Windows 7, but which version, which patches and updates, etc.) and which version of Java,

    The fact that you had a zero byte file bothers me since a quick look at the code suggests that should be detected and dealt with, so I will spend some more time investigating.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •