{"record":{"id":"edf5c7e64ca84771","repo":"stanfordnlp/CoreNLP","slug":"could-not-annotate-via-server","errorCode":null,"errorMessage":"Could not annotate via server!","messagePattern":"Could not annotate via server!","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/StanfordCoreNLPClient.java","lineNumber":463,"sourceCode":"        serializer.write(annotation, os);\n        os.close();\n        byte[] message = os.toByteArray();\n        // 1.2 Create the query params\n\n        String queryParams = String.format(\"properties=%s\",\n                                           URLEncoder.encode(StanfordCoreNLPClient.this.propsAsJSON, \"utf-8\"));\n\n        // 2. Create a connection\n        URL serverURL = new URL(backend.protocol, backend.host, backend.port,\n                                StanfordCoreNLPClient.this.path + '?' + queryParams);\n\n        // 3. Do the annotation\n        //    This method has two contracts:\n        //    1. It should call the two relevant callbacks\n        //    2. It must not throw an exception\n        doAnnotation(annotation, backend, serverURL, message);\n      } catch (Throwable t) {\n        log.err(\"Could not annotate via server!\", t);\n        if (fallbackToLocalPipeline) {\n          log.info(\"Trying to annotate locally...\");\n          StanfordCoreNLP corenlp = new StanfordCoreNLP(properties);\n          corenlp.annotate(annotation);\n        } else {\n          annotation.set(CoreAnnotations.ExceptionAnnotation.class, t);\n        }\n      } finally {\n        callback.accept(annotation);\n        isFinishedCallback.accept(backend);\n      }\n    }).start());\n  }\n\n  static final int MAX_TRIES=3;\n\n  /**\n   * Actually try to perform the annotation on the server side.","sourceCodeStart":445,"sourceCodeEnd":481,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/StanfordCoreNLPClient.java#L445-L481","documentation":"StanfordCoreNLPClient.annotate caught a Throwable while sending the annotation request to the CoreNLP server (connection failure, HTTP error, bad response, timeout, etc.). If fallbackToLocalPipeline is enabled it retries locally; otherwise the Throwable is stored in ExceptionAnnotation on the annotation and this message is logged.","triggerScenarios":"Using StanfordCoreNLPClient with -backends/server URL where the server is down, wrong port, rejecting the request (e.g. unsupported serializer, oversized payload, annotator not loaded on server), or the connection drops mid-call; doAnnotation throwing inside annotate().","commonSituations":"Server not started or wrong -server/-port; request exceeding server's max payload or timeout; client/server CoreNLP version mismatch; firewall/proxy blocking the HTTP call; forgetting to start the server before running the client.","solutions":["Verify the server is running and reachable: check the configured -host/-port (default http://localhost:9000)","Read the attached Throwable (logged after the message or in ExceptionAnnotation) for the real cause","Start the server with matching annotators/properties and compatible CoreNLP version","Enable fallbackToLocalPipeline=true to annotate locally when the server fails","Check payload size/timeouts; split very large documents into smaller requests"],"exampleFix":"// before\nprops.setProperty(\"annotators\", \"tokenize,ssplit,pos\");\nStanfordCoreNLPClient client = new StanfordCoreNLPClient(props, \"http://localhost\", 9001, 2);\n// after\nprops.setProperty(\"annotators\", \"tokenize,ssplit,pos\");\nprops.setProperty(\"fallbackToLocalPipeline\", \"true\");\nStanfordCoreNLPClient client = new StanfordCoreNLPClient(props, \"http://localhost\", 9000, 2);","handlingStrategy":"fallback","validationCode":"// health check before annotating\nHttpURLConnection c = (HttpURLConnection) new URL(serverUrl + \"/ping\").openConnection();\nc.setConnectTimeout(3000);\nif (c.getResponseCode() != 200) throw new IllegalStateException(\"CoreNLP server unreachable at \" + serverUrl);","typeGuard":null,"tryCatchPattern":"try {\n    client.annotate(annotation);\n} catch (Throwable t) {\n    log.err(\"Could not annotate via server!\", t);\n    new StanfordCoreNLP(props).annotate(annotation); // local fallback\n}","preventionTips":["Start the server and verify /ping before running client batches","Match client and server CoreNLP versions","Set fallbackToLocalPipeline=true for resilient jobs","Split very large documents and configure timeouts appropriately"],"tags":["network","http-client","server","fallback"],"backgroundTag":"http-request-failed","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}