Netbeans points to error in the class ConferenceSchedulingConstraintProvider.java int ht method:
private Constraint talkPrerequisiteTalks(ConstraintFactory factory) {
return factory.from(Talk.class)
.join(Talk`enter code here`.class,
containing(Talk::getPrerequisiteTalkSet, Function.identity()),
lessThan(talk1 -> talk1.getTimeslot().getStartDateTime(),
talk2 -> talk2.getTimeslot().getEndDateTime()))
.penalizeConfigurable(TALK_PREREQUISITE_TALKS,
Talk::combinedDurationInMinutes);
}
Your language level is probably not set to at least Java 8.
Open the project's setting and set it to java 8 or higher.
Related
I know that similar questions have been asked (here, here, here), but none of the answers seem to apply to my case.
Consider the following set of interfaces:
public interface I1<X> {
void method(X arg);
}
public interface I2 {
void method(String arg);
}
public interface I3 extends I1<String>, I2 {
// empty
}
Now I want to call method(String) on an instance of I3, like so:
public class C implements I3 {
public void method(String arg) {
// does nothing
}
public static void main(String[] args) {
((I3) new C()).method("arg");
}
}
The OpenJDK (Java 7 or 8, doesn't matter) flags an incompatibility error here:
generics\C.java:10: error: reference to method is ambiguous
((I3) new C()).method("arg");
^
both method method(String) in I2 and method method(X) in I1 match
where X is a type-variable:
X extends Object declared in interface I1
Since X is instantiated to String in I3, I do not see where the problem comes from. Note that Eclipse considers this to be fine.
The answer to the question, "why?" is simple but probably not what you're looking for. It is, "Because Eclipse and Open JDK each have their own compilers and either a) one of them has a bug or b) the language specification (JLS) is ambiguous and they've interpreted it differently."
Figuring out which of a) or b) is the case is a tricky, tedious task. It means, as a starting point, reading the relevant sections of the JLS, trying to compile the same code with Oracle JDK's javac, and possibly diving into the bug tracking systems of Eclipse and OpenJDK.
Working on a GWT project (2.7.0), i have experienced a very odd client code behaviour.
The following code throws the error "SEVERE: (ReferenceError) : Ljava_io_Serializable_2_classLit_0_g$ is not definedcom.google.gwt.core.client.JavaScriptException: (ReferenceError) : Ljava_io_Serializable_2_classLit_0_g$ is not defined".
The error occurs, when calling Arrays.asList() with a parameter, that has an interface type.
Is this expected behaviour or a GWT bug?
// Working
Integer n1 = 1;
Arrays.asList(n1);
// Not working
Serializable n2 = 1;
Arrays.asList(n2);
GWT 2.7's Super Dev Mode (and from the _g$ in your class literal field, I think that is what you are using) has been observed having other issues like this, but when compiled the issues go away.
If this is indeed what you are seeing, the issue seems to be fixed in 2.8, not yet released: https://groups.google.com/d/topic/google-web-toolkit/RzsjqX2gGd4/discussion
This behavior is definitely not expected, but if you can confirm that this works correctly when compiled for production and in GWT 2.8, then we at least know the bug is fixed.
Well, the typical use of Arrays.asList would be
Object myObj = new Object();
List theList = Arrays.asList(new Object[] {myObj});
This works in GWT with any kind of interface/class/enum you throw at it.
EDIT : I've tested this with GWT 2.5.1 :
public class Foo implements EntryPoint {
public static interface MyInterface {
}
public static class MyObject implements MyInterface {
}
public void onModuleLoad() {
MyInterface myObject = new MyObject();
List<MyInterface> myList = Arrays.asList(myObject);
}
}
Isn't it possible that the problem lies somewhere else?
I found the bytecode compiled from ECJ compiler has the annotation information missing.
The source code decompiled from bytecode compiled by javac:
public class HelloWorldApp {
#GetAction("/hello")
public String sayHello() {
return "Hello World!";
}
}
The source code decompiled from bytecode compiled by ECJ:
public class HelloWorldApp {
public String sayHello() {
return "Hello World!";
}
}
So clearly the annotation #GetAction("/hello") is missing from the bytecode compiled by ECJ (in memory compilation).
Anyone has encountered this issue before and get any clue?
Update with more information
Take a look at the following screenshot:
So it is in the ASTNode.resolveAnnotations() methods line #797:
A) The state if ((method.tagBits & TagBits.AnnotationResolved) != 0) return annotations; will return null as annotations even
B) the source annotation #GetAction("/hello") is presented because
C) the this.annotations field is null and
D) the if condition (method.tagBits & TagBits.AnnotationResolved) != 0 evaluates to true
Updates 2
It looks like I captured the screen too early, so once process finished, I found the annotations information get stored:
However I still can't get the annotation information from the result file. Click here to download the bytecode file generated:
Note I am using ECJ 4.4.1:
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>4.4.1</version>
</dependency>
Problem solved! Just add the following lines:
opt(map, OPTION_TargetPlatform, "1.6");
The issue is caused by default JDK version is 1.2 in ECJ, which does not support annotation
I am working on JavaCard applet and I am facing a strange error in my NXP JCOP Tools Eclipse plugin:
It says: "no definition for label Label: XXXXXXXX, , block XXX, def null".
Do you have any idea what it could mean? Eclipse underlines the package name, but I am absolutely sure that the package name is correct and that the class is in the correct package. There is no other error in the whole project (From 11 errors above there are 2 of type "no definition for label Label: ..." and other 9 directly caused by these 2). I tried cleaning and refreshing the project and deleting all binaries, but it does not help.
In the "Type" column there is: "com.ibm.bluez.jcop.eclipse.jcopmarker".
My Eclipse version:
Version: 4.2.2
Build id: M20130204-1200
I solved the issue, I hope it might help someone. I changed my method code from
public boolean processAPDU(APDU apdu) {
final byte[] apduBuf = apdu.getBuffer();
switch(apduBuf[ISO7816.OFFSET_INS]) {
...
to
public boolean processAPDU(APDU apdu) {
final byte[] apduBuf = apdu.getBuffer();
final byte ins = apduBuf[ISO7816.OFFSET_INS];
switch(ins) {
...
and the error is gone. Possibly a bug in NXP JCOP Tools?
In Eclipse Helios I have 3 classes all in the same project which is in the same workspace.
The classes are ("path" and "location" found in properties dialogue of each class)
A
path: /myproject/src/a/A.java
location: /home/me/dev/myrepo/somefolder/myproject/src/a/A.java
R1
path: /myproject/src/b/R1.java
location: /home/me/dev/myrepo/somefolder/myproject/src/b/R1.java
R2
path: /myproject/src/b/R2.java
location: /home/me/dev/myrepo/somefolder/myproject/src/b/R2.java
A has a method f, which is used by methods in both R1 and R2.
If, with mouse over method f() of A, I do right click -> References -> Workspace (Shift+Ctrl+G) or right click -> References -> Project, it only shows R1 in the results pane.
What could any possible reasons for this be? Are there any configurations I should change? I use grep and I can find both references. Perhaps Eclipse does something ghetto like using grep underneath and doesn't actually analyse the source code?
I already tried refreshing the project (in case you're thinking I edited R2 outside of Eclipse), didn't help.
I can't post the real source because it's super secret. Here is some equivalent source (though the problem didn't happen with these ones):
A.java
package a;
public class A {
public void f() {}
}
R1.java
package b;
import a.A;
public class R1 {
void f() {
new A().f();
}
}
R2.java
package b;
import a.A;
public class R2 {
void f() {
new A().f();
}
}