Eclipse is giving me a warning of the following form:
Type safety: Unchecked cast from Object to HashMap<String, String>
This is from a call to an API that I have no control over which returns Object:
HashMap<String, String> getItems(javax.servlet.http.HttpSession session) {
HashMap<String, String> theHash = (HashMap<String, String>)session.getAttribute("attributeK...
Sometime when looking through code, I see many methods specify an annotation:
@SuppressWarnings("unchecked")
What does this mean?
FindBugs has found a potential bug in my code. But it is not a bug.
Is it possible to mark this occurrence as 'not a bug' AND have it removed from the bug list?
I have documented quite clearly why for each case it is not a bug.
For example. A class implements the comparable interface. it has the compareTo method. I have however not overridden the equals method.
FindBugs does not like this a...
I was wondering if scala had an equivalent to java's @SuppressWarnings that can be applied to a function or whatever to ignore any deprecation warnings[1] that function emits?
1: Relevant warning in my case is: method stop in class Thread is deprecated: see corresponding Javadoc for more information. I am aware of the problems with stop however there are still some cases where due to legacy co...
When I compile, javac outputs:
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.`
I wish to suppress this warning. Trying -Xlint:none does not seem to help
I try to get my code to compile with no errors and no warnings as standard practice. There is one annoying warning, though, that I know how to deal with in .NET but not in Java. Say I have a code block like this:
try {
FileInputStream in = new FileInputStream(filename);
return new Scanner(in).useDelimiter("\\A").next();
} catch (FileNotFoundException ex) {
LOG...
We are always taught to make sure we use a break in switch statements to avoid fall-through.
The Java compiler warns about these situations to help us not make trivial (but drastic) errors.
I have, however, used case fall-through as a feature (we don't have to get into it here, but it provides a very elegant solution).
However the compiler spits out massive amounts of warnings that may obsc...
Netbeans provides a lot of custom "hints", which are like warnings, only that most of them can't be suppressed (just disabled IDE-globally).
But now I looking at code which uses
@SuppressWarnings("element-type-mismatch")
to suppress a hint/warning which is called "suspicious method call" (such as remove(...) for a collection with a "wrong" type).
Well, I would never come to the idea to sup...
In my Eclipse project are a handful of generated .java files that I need to use for SQLJ and I can't move to a separate project (due to Administrative Overhead). These files are also regularly regenerated so editing them is unfortunately out.
Unfortunately these files generate a few hundred java compiler warnings which drown out the useful warnings I get on files that I actually can edit.
Is...
I have the following code:
public abstract class A<T extends B<? extends A<T>>>{
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
A other = (A) obj; // warning here: "A is a raw type"
// ...
i have the following line of code which displays the following warning:
HashMap<String,String> currentItem = (HashMap<String,String>) adapter.getItemAtPosition(position);
// Warning: Type Safety: Unckecked cast from Object to HashMap <String,String>
How can i get rid of this warning?
As part of my Utils class, i have both
public static boolean isStringEmptyOrNull(String... s) {
When testing for a null condition
assertTrue(Utils.isStringEmptyOrNull(null));
I get "The argument of type null should explicitly be cast to String[] for the invocation of the varargs method isStringEmptyOrNull(String...) from type Utils. It could alternatively be cast to String for a varargs i...
It is possible to hide the warning messages in java?
Try to write:
List<Object> list;
@SuppressWarnings("unchecked")
list = (List<Object>) new Object();
It will fail on the 3rd line, on the word list, with the following:
list cannot be resolved to a type
I understand that it is related to how annotations work. Anybody knows the reasoning behind this?
EDIT: thanks for the fast answer. I knew it'd work if the assignment was made a...