Java unchecked or unsafe operations message

user2351151 picture user2351151 · May 13, 2013 · Viewed 23.1k times · Source

I am getting the following error when compiling a Java class in BlueJ.

AuctionManager.java uses unchecked or unsafe operations.

This error is only displayed when the following deserialization code is in one of my functions:

try {
  ObjectInputStream in = new ObjectInputStream(new FileInputStream(Filename));
  ArrayList<AuctionItem> AuctionList = (ArrayList<AuctionItem>) in.readObject();
  in.close();
}
catch (Exception e) {
  e.printStackTrace();
}

Can I please have some information as to why this error is being displayed, and some help to use the deserialization code without the error.

Answer

zw324 picture zw324 · May 13, 2013

First the message you get is not an error, is it a warning; it doesn't prevent you program from compiling, or running.

As for the source, it is this line:

ArrayList<AuctionItem> AuctionList = (ArrayList<AuctionItem>) in.readObject();

Since you are casting an object (readObject returns an Object) to a parameterized type (ArrayList<AuctionItem>).