title: stanford corenlp serialization exception
body: <p>I am using the Stanfrod coreNLP's ProtobufAnnotationSerializer to serialize/deserialize Annotation objects, it works fine most of the times, but some times the serializer gives me the next Index Out Of Bounds Exception:</p>
  
  <pre><code>    java.lang.IndexOutOfBoundsException: Index: 44, Size: 36
  at java.util.ArrayList$SubList.rangeCheck(ArrayList.java:1217)
  at java.util.ArrayList$SubList.get(ArrayList.java:1034)
  at edu.stanford.nlp.pipeline.ProtobufAnnotationSerializer.fromProto(ProtobufAnnotationSerializer.java:1513)
  at edu.stanford.nlp.pipeline.ProtobufAnnotationSerializer.fromProto(ProtobufAnnotationSerializer.java:1588)
  at edu.stanford.nlp.pipeline.ProtobufAnnotationSerializer.fromProto(ProtobufAnnotationSerializer.java:1296)
  at edu.stanford.nlp.pipeline.ProtobufAnnotationSerializer.read(ProtobufAnnotationSerializer.java:186)
  at com.marca.nlp.relation.RelationDBDeser.main(RelationDBDeser.java:102)
  </code></pre>
  
  <p>This exception popups up frequently and for no clear reasons that I could find, here is my serialize/deserialize code:</p>
  
  <p>Serialize: </p>
  
  <pre><code>    Properties props = new Properties();
      props.setProperty("annotators", "tokenize,ssplit, pos, lemma, ner, parse"
             + ", depparse, mention, coref, natlog, openie, relation, sentiment");
      props.setProperty("openie.resolve_coref", "true");
      StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
  
      ProtobufAnnotationSerializer serializer = new ProtobufAnnotationSerializer();
  
      String docPath = "document.proto";
       try{
  
              Annotation document = new Annotation(input);
  
              pipeline.annotate(document);
  
              FileOutputStream fileOut = new FileOutputStream(docPath);
              ObjectOutputStream out = new ObjectOutputStream(fileOut);
              serializer.write(document, out);
      } catch (Exception ex){
              ex.printStackTrace();
      }
  </code></pre>
  
  <p>Deserialize code:</p>
  
  <pre><code>    ProtobufAnnotationSerializer serializer = new ProtobufAnnotationSerializer();
      try{
          String docPath = "document.proto";
          FileInputStream fileIn = new FileInputStream(docPath);
          ObjectInputStream in = new ObjectInputStream(fileIn);
  
          Pair&lt;Annotation, InputStream&gt; docs = serializer.read(in);
          Annotation document = docs.first();
      } catch(Exception ex){
          ex.printStackTrace();
      }
  </code></pre>
  
  <p>The exception pops up when I deserialize the object, here is a sample text that causes the problem:</p>
  
  <blockquote>
    <p>Alice Corp. v. CLS Bank International was a legal case about patentable subject matter (patent eligibility)  that the United States Supreme Court heard in 2014, presenting the issue of whether certain claims about a computer-implemented, electronic escrow service for facilitating financial transactions concern abstract ideas ineligible for patent protection.  The patents were held to be invalid because the claims were drawn to an abstract idea, and implementing those claims on a computer was not enough to transform that idea to a patentable invention.  It was the first Supreme Court case on the patent eligibility of software since Bilski v. Kappos in 2010, which was the first such case in three decades.    Alice Corporation ("Alice") owns four patents on electronic methods and computer programs for financial-trading systems on which trades between two parties who are to exchange payment are settled by a third party in ways that reduce "counterparty" or "settlement" risk, or the risk that one party will perform while the other will not. According to Alice's account, CLS Bank International and CLS Services Ltd. (collectively "CLS Bank") began to use a similar technology in 2002. Alice notified CLS Bank of its probable infringement of Alice's patents, and the companies discussed licensing of the patents.  The relevant claims are in these patents: The three later patents are all derived from the first through continuation and/or continuation-in-part applications. The concept of a third-party to confirm a complete transaction is called escrow, and has been used in finance for thousands of years. The patents in question described how the escrow function could be performed by a general-purpose computer. However, they did not describe how such a computer would work, and did not include any source code or specifications. Australian Ian Shepherd received the patents in 1999, and then formed Alice Corporation to own the patent. However, Alice never produced any such computer system as described, or used the patents in any of its business. As a result the company has been called a patent troll. CLS, a consortium of banks, has actually developed such a computer system that it uses to facilitate US$5 trillion in transactions every day.  US Patent law specifies several requirements before something can receive a patent. 35 U.S.C. §101 of the federal patent law has been interpreted as implicitly disqualifying abstract ideas from being patented and forbidding patents on laws of nature and physical phenomena. 35 U.S.C. §102 requires the submission to be novel, and sets out conditions for what can be used as prior art. 35 U.S.C. §103 requires that patentable claims should not be obvious to someone familiar with the subject. 35 U.S.C. §112 requires (among others) that patents must be clear and detailed enough for someone familiar with the subject to implement it. Alice Corporation's patents have been argued invalid under all of these sections, but the primary litigation focus has been on Section 101 and if Alice's patents claim an abstract idea.  In 2007, CLS Bank sued Alice in the United States District Court for the District of Columbia seeking a declaratory judgment that Alice's patents were invalid and unenforceable and that CLS Bank had not infringed them. Alice countersued CLS Bank for infringement of the patents. After the court had allowed initial, limited discovery on the questions of CLS Bank's operations and its relationship to the allegedly infringing CLS Bank system, the court ruled on the parties' cross-motions for summary judgment, declaring each of Alice's patents invalid because the claims concerned abstract ideas, which are not eligible for patent protection under 35 U.S.C. § 101.  The court stated that a method “directed to an abstract idea of employing an intermediary to facilitate simultaneous exchange of obligations in order to minimize risk” is a “basic business or financial concept,” and that a “computer system merely ‘configured’ to implement an abstract method is no more patentable than an abstract method that is simply ‘electronically’ implemented.”  The district court judge followed Bilski v. Kappos as precedent, in which the 2010 Supreme Court held that certain claims to business methods for hedging against the risk of price fluctuations when trading in commodities markets were not patent-eligible because they covered the abstract idea of hedging against risk.  In the Bilski case the Supreme Court had said that allowing such claims would preempt the use of risk-hedging in all fields and grant a monopoly over an abstract idea.  Alice appealed the decision and the case went to the United States Court of Appeals for the Federal Circuit. A panel of the appeals court decided by 2-1 in July 2012 to reverse the lower court's decision. The panel held that computer-implemented inventions like Alice's are patent-eligible under § 101 unless it is “manifestly evident” that the claims are about an abstract idea; that is, “the single most reasonable understanding is that a claim is directed to nothing more than a fundamental truth or disembodied concept, with no limitations in the claim attaching that idea to a specific application.”  CLS Bank petitioned the same Federal Circuit court for an en banc rehearing. The court granted the petition and vacated the earlier panel's decision in order to decide the following questions: what test should the court adopt to determine whether a computer-implemented invention is a patent-ineligible abstract idea; whether the presence of a computer in a claim could ever make patent-ineligible subject matter patentable; and whether method, system, and media claims should be considered equivalent under § 101. The fractured panel of ten judges issued seven different opinions, with no opinion supported by a majority. Seven of the ten judges upheld the district court's decision that Alice's method claims and computer-readable-medium claims were not patent-eligible, but they did so for conflicting and incompatible reasons. Five of the ten judges upheld the district court's decision that Alice's computer-systems claims were not patent-eligible. The panel did not agree on a standard to determine whether a computer-implemented invention is a patent-ineligible, abstract idea.  In the leading, five-member, concurring opinion by Circuit Judge Lourie, joined by Circuit Judges Dyk, Prost, Reyna, and Wallach, a plurality of the court articulated an analysis of patent-eligibility focused on first identifying the abstract idea or fundamental concept applied by the claim and then determining whether the claim would preempt the abstract idea.  The analysis involves four steps: Regarding "human contribution," the Lourie opinion pointed to four questions to ask, which are potentially subjective factors weighing against patent-eligibility: The Lourie analysis is framed by three common themes in Supreme Court decisions: Chief Judge Rader and Circuit Judges Linn, Moore, and O'Malley filed an opinion concurring in part and dissenting in part, which articulated a patent-eligibility analysis focused on determining whether the claim, as a whole, was limited to an application of an abstract idea, or was merely a recitation of the abstract idea. Under the Rader approach, Alice's patents would have been held patent-eligible because the system claims were limited to a computer-implemented application.  Judge Rader filed "additional reflections" to the ruling (not signed by other judges) expressing his read of the statute as allowing very broad patentability under § 101, and his understanding that natural laws are restricted to "universal constants created, if at all, only by God, Vishnu, or Allah." Referencing Einstein, he states that "even gravity is not a natural law.".  —Circuit Judge Kimberly Ann Moore, dissenting in part,   Circuit Judge Moore filed an opinion dissenting in part, in which Chief Judge Rader and Circuit Judges Linn and O'Malley joined, which stated, based on reasoning similar to the Rader approach, that a claim must be considered as a whole and that Alice's computer-systems claims should have been ruled patent-eligible. The opinion cautioned that "if all of these claims, including the system claims, are not patent-eligible, this case is the death of hundreds of thousands of patents, including all business method, financial system, and software patents as well as many computer implemented and telecommunications patents."  Circuit Judge Newman filed an opinion concurring in part and dissenting in part, which called for the Federal Circuit to clarify the interpretation of § 101 by affirming three fundamental principles: that § 101 is an inclusive statement of patentable subject matter, that the form of the claim is not relevant to patent-eligibility, and that experimental use of patented subject matter, such as experiments that improve or build upon patented subject matter, compare it with alternatives, seek to understand its mechanisms, or seek to find new applications of it, is not patent-ineligible.  Circuit Judges Linn and O'Malley filed a dissenting opinion that, for procedural reasons, the lower court should have been reversed and all claims ruled patent-eligible. The opinion agreed with the Rader opinion with respect to the computer-systems claims but would have applied the Rader analysis to all the claims and would have had all claims rise or fall together. The opinion called for legislative, rather than judicial, action to address the "proliferation and aggressive enforcement of low quality software patents" cited in the many amicus curiae briefs and suggested laws to limit the term of software patents or limit the scope of patents by requiring functional claiming.  The Supreme Court of the United States granted Alice's petition for a writ of certiorari to decide the question "[w]hether claims to computer-implemented inventions—including claims to systems and machines, processes, and items of manufacture—are directed to patent-eligible subject matter within the meaning of 35 U.S.C. § 101."  The deep interest of the software industry and patent experts in this divisive issue is evident in the number of companies and groups that had filed amicus curiae briefs urging the Supreme Court to decide this issue, including, among others, Electronic Frontier Foundation, Software Freedom Law Center, Institute of Electrical and Electronics Engineers, Intellectual Property Law Association of Chicago, and Accenture Global Services.  While nearly all such briefs argued that the patent should be invalidated, they disagreed on the reasoning. A brief prepared by Google, Amazon and other companies argued that the patent was of an abstract idea, which actually harms innovation, and that the real innovation lies in detailing out a working system. Microsoft, Adobe and Hewlett-Packard argued it was nothing more than an unpatentable business method (per Bilski v. Kappos) and merely saying to perform it with a computer does not change this fact. Linkedin, Netflix and others, and a separate brief by the Free Software Foundation and others both argued that no software should be patented, as this blocks innovation and scientific collaboration. IBM disagreed with the "abstract ideas" reasoning and argued that the patent should instead be struck down for being too obvious. Finally, a consortium of retailer and manufacturers, including Dillard's and Hasbro, simply asked for a clear rule.  The Court heard oral arguments in the case on March 31, 2014,  and issued a ruling on June 19, 2014.  Arguing for Alice Corp. was Carter G. Phillips of Sidley Austin, and arguing for CLS Bank is Mark A. Perry of Gibson, Dunn &amp; Crutcher. The court agreed with those filing amicus curiae briefs and unanimously invalidated the patent. According to The Washington Post, "while the court struck down what was universally said to be a bad patent, it didn't do much to say what kinds of software should be patentable. In other words, the court decided the most basic conflict in the case, but more or less declined to offer guidance for other, future cases."  The Electronic Frontier Foundation said the Supreme Court "reaffirmed that merely adding “a generic computer to perform generic computer functions” does not make an otherwise abstract idea patentable. This statement (and the opinion itself) makes clear that an abstract idea along with a computer doing what a computer normally does is not something our patent system was designed to protect. Admittedly, the Supreme Court did not offer the clearest guidance on when a patent claims merely an abstract idea, but it did offer guidance that should help to invalidate some of the more egregious software patents out there."  The Software Freedom Law Center said the Supreme Court "took one more step towards the abolition of patents on software inventions. Upholding its previous positions, the Court held that abstract ideas and algorithms are unpatentable. It also emphasized that one cannot patent “an instruction to apply [an] abstract idea ... using some un-specified, generic computer.”"  The Coalition for Patent Fairness, which advocates for patent reform legislation, said "neither the ruling—nor any single act by the court or the executive branch—can do what is needed to make the business model of being a patent troll unprofitable and unattractive."  Some commentators expressed disappointment with the opinion for its failure to define more comprehensively the boundaries between abstract ideas and patent-eligible implementations of ideas. They were particularly critical of Justice Thomas's statement—"In any event, we need not labor to delimit the precise contours of the 'abstract ideas' category in this case. It is enough to recognize that there is no meaningful distinction between the concept of risk hedging in Bilski and the concept of intermediated settlement at issue here. Both are squarely within the realm of 'abstract ideas' as we have used that term."  For example, Professor Merges said, “To say we did not get an answer is to miss the depth of the non-answer we did get.”  Professor Duffy remarked, "[T]he Supreme Court has been remarkably resistant to providing clear guidance in this area, and this case continues that trend."  Perhaps most exasperated of all was Law Comics, which cartooned Justice Thomas saying that "we need not labor..." and replied "yes you do!" while wagging a finger at him as an accompanying article asserted that his opinion “baulked at the messy, challenging issues surrounding software” and was “not a particularly useful” decision about patenting software.  On the other hand, Professor Stern defended the opinion as "the expectable price of unanimity in a nine-member tribunal," arguing that the "greater sensed legitimacy and precedential stability" of a unanimous opinion "outbalanced" the shortcomings of a lack of clear guidance as to details; this commentator also asserted that "it is sensible to make narrow, incremental rulings as to software patent eligibility, because at present we are not so well informed that we can speak with confidence in very broad terms."</p>
  </blockquote>
  
  <p>I am using Stanford CoreNLP 3.6.0
  Any thoughts?</p>