Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » [Neon] Java Compiler Error(The blank final field values may not have been initialized)
[Neon] Java Compiler Error [message #1723510] Tue, 16 February 2016 10:20 Go to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
I have noticed that following code does not compile with Neon.M5:

package tmp;

import java.util.ArrayList;
import java.util.List;

public class SomeClass {

	private final List<Object> values;

	public SomeClass() {
		values = new ArrayList<>();
	}
	
	public SomeClass(Object arg) {
		if(arg instanceof SomeClass) {
			values = ((SomeClass)(arg)).values; //Compile error here.
		} else {
			throw new IllegalArgumentException("arg is not instance of SomeClass");
		}
	}
}


I get this error on the "values" variable after the cast "((SomeClass)(arg))":

Quote:
The blank final field values may not have been initialized


This is a problem I do not have with the Mars.1 Version.

I can compile this class with javac:
> javac -version
javac 1.8.0_66

> javac SomeClass.java


The workaround is to assign the casted class to a variable:

package tmp;

import java.util.ArrayList;
import java.util.List;

public class SomeClass {

	private final List<Object> values;

	public SomeClass() {
		values = new ArrayList<>();
	}
	
	public SomeClass(Object arg) {
		if(arg instanceof SomeClass) {
			SomeClass someClass = (SomeClass)(arg);
			values = someClass.values;
		} else {
			throw new IllegalArgumentException("arg is not instance of SomeClass");
		}
	}
}


Is this an already known bug?
What is the proper way to report it?

Thank you in advance.

[Updated on: Tue, 16 February 2016 10:26]

Report message to a moderator

Re: [Neon] Java Compiler Error [message #1723523 is a reply to message #1723510] Tue, 16 February 2016 11:37 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
This looks like a variant of https://bugs.eclipse.org/486908
I'll add a cross-reference there.
Stephan
Previous Topic:Differences between Oracle and Eclipse compiler
Next Topic:Stepping thru external jar...
Goto Forum:
  


Current Time: Fri Apr 26 16:11:34 GMT 2024

Powered by FUDForum. Page generated in 0.02792 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top