google-code-export / umple

Automatically exported from code.google.com/p/umple
1 stars 0 forks source link

Uninitialized const variable does not throw a warning #424

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When compiling the following code:
class Const_class_null{
    const int e;
}

You get the following output (in Java):

public static final int e = null;

This is correct, however it is also useless. The user most likely will try to 
initialize the variable later on, which will fail. For this reason I propose 
that we throw a warning when we see an uninitialized const variable.

Original issue reported on code.google.com by glkleens...@gmail.com on 20 Sep 2013 at 3:01

GoogleCodeExporter commented 9 years ago
See also issue 425

Original comment by TimothyCLethbridge on 21 Sep 2013 at 12:06

GoogleCodeExporter commented 9 years ago
The above example actually does not work with an interface. 

interface Const_class_null{
    const int e;
}

gives us 

const int e;

We will also need to fix this to give the expected output,

public static final int e = null;

Original comment by glkleens...@gmail.com on 21 Sep 2013 at 4:44

GoogleCodeExporter commented 9 years ago
Bellow is a partial fix for this issue. Specifically it throws a warning when a 
const value is declared but not initialized within a class.

Original comment by glkleens...@gmail.com on 21 Sep 2013 at 6:50

Attachments:

GoogleCodeExporter commented 9 years ago
Fixed as of revision 3239.

The following values are now set for various types of constants:
0 for Integer, Double or Float
Empty string for String
False for Boolean
Midnight (00:00:00) for Time
The current date for Date

For non-default types no default is set and error 37 is thrown.

Original comment by glkleens...@gmail.com on 27 Nov 2013 at 5:23

GoogleCodeExporter commented 9 years ago

Original comment by glkleens...@gmail.com on 15 Dec 2013 at 11:30