Compile error, 'tree' can't be resolved...can't figure out what's going on!
scasadei opened this issue · 11 comments
Hello, I have just cloned CoreNLP from github into the most recent Eclipse environment (2023-09), and I am getting the compilation error shown in the attached image (Java 20 compiler). I can't figure out what's going on! The first reference to tree is OK, the following ones can't be resolved, even though they are in the same compile scope! Same errors occurred in an older eclipse environment (2022-12) with the Java 19 compiler.
A very similar error occurs in class AnCoraPOSStats, in block:
for (File file : fileList) { }
Thanks for your help
Honestly I don't have the slightest idea. It looks like legal Java to me, but no one ever hired me to be a Java compiler.
What happens if you comment out a line such as 91, if(tree.yield().size() > maxLen) continue;
Maybe Eclipse is incorrectly thinking the loop always shortcuts there?
Or a different variable name? No idea if something weird happened where that variable name was used elsewhere and that is confusing Eclipse
What if you took the variable out of the loop and only did the operations once? Would it compile then? (Obviously the functionality would be broken)
Hmm, I had actually meant to remove the loop and test compiling with nothing there, but this might still be useful to know.
If memory serves, yield
is actually now a keyword in future versions of Java. (Anything after 8 is "future" from our point of view.) Perhaps there is some effect going on here. Each of the examples you've pasted so far has that in the error.
In the case of the one where the line has yield().size()
, would you try replacing that with taggedYield().size()
? If that clears up some of the errors, I'll put a little effort into generalizing it, especially if you can help point out where the compiler is spazzing.
Incidentally, handling this error is kinda reinforcing my belief that pasting images is a lot less useful than pasting text - I wanted to copy/paste the line I wanted to change, but couldn't
Good point, I will include text from now on.
Tried to remove the whole loop, all the errors disappear.
Here is the text where the four errors occur (lines 95,98,101,104)
91 for (Tree tree : tb) {
92 if(tree.yield().size() > maxLen) continue;
93 ++numTrees;
94 if (printTrees) {
95 pw.println(tree.toString());
} else if (flattenTrees) {
pw.println(SentenceUtils.listToString(tree.yield()));
} else if (printPOS) {
pw.println(SentenceUtils.listToString(tree.preTerminalYield()));
} else if (printTnT) {
List<CoreLabel> yield = tree.taggedLabeledYield();
for (CoreLabel label : yield) {
pw.printf("%s\t%s%n", label.word(), label.tag());
}
pw.println();
}
}
And the same error occurs in the class AnCoraPOSStats, at line 51 (below),
there is yield in this instance. The two instances have in common that the variable
is declared with the colon syntax inside of for (....)
48 Tree t;
49 for (File file : fileList) {
50 Reader in =
51 new BufferedReader(new InputStreamReader(new FileInputStream(file), ANCORA_ENCODING));
TreeReader tr = trf.newTreeReader(in);
// Tree reading will implicitly perform tree normalization for us
while ((t = tr.readTree()) != null) {
// Update tagger with this tree
List<CoreLabel> yield = t.taggedLabeledYield();
for (CoreLabel leafLabel : yield) {
if (leafLabel.tag().equals(SpanishTreeNormalizer.MW_TAG))
continue;
unigramTagger.incrementCount(leafLabel.word(), leafLabel.tag());
}
}
}
}
What happens if you try this one
92 if(tree.yield().size() > maxLen) continue;
with getLeaves()
instead of yield()
? That one would be an easy fix if it's the yield
keyword causing the problem, since the effect should be exactly the same.
Would you try compiling the dev branch? I removed two usages of the keyword yield
from in those functions. If that improves the compilation, I can do the same in any other places you find a compile error.
The dev branch does not trigger the error, thanks for finding a solution!
There is still one error that pops up in file OSXAdapter:
private static com.apple.eawt.Application app can not be resolved,
I will open a new issue for it