2

I have this code:

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.Date;

public class EmployeeProcessor {
    public static void main(String[] args) {
        Employee employee = new Employee();
        employee.lastName = "Smith";
        employee.firstName = "Adam";
        employee.id = 123456789;
        employee.salary = 50000;

        try(FileOutputStream fileOutStr = new FileOutputStream("Employee.ser");
            ObjectOutputStream objectOutStr = new ObjectOutputStream(fileOutStr)) {

            objectOutStr.writeObject(employee);
            System.out.println("An employee is externalized into the file Employee.ser");

        } catch (IOException ioError){
            ioError.printStackTrace();
        }
    }
}

But in Intellij IDEA ObjectOutputStream class is strikethrough Like this: screenshot. When pointing mouse pointer over - this message appears: 'java.io.ObjectOutputStream' is deprecated. What does it mean?

When I run this code, IntelliJ opens "Edit Configurations" windows asking me to introduce VM options. But I leave it blank and run anyway.

Vitali Plagov
  • 722
  • 1
  • 12
  • 31
  • 1
    If somethings deprecated, it means it's obsolete/dangerous to use. A quick search though shows that while that class contains deprecated methods, the class itself doesn't appear to be deprecated. This might be a IntelliJ bug. – Carcigenicate Jan 16 '17 at 20:29
  • List of deprecated items in Java 8: [Deprecated list](https://docs.oracle.com/javase/8/docs/api/deprecated-list.html) – Vüsal Jan 16 '17 at 20:34
  • @Vusal, thank you for the link. But class `ObjectOutputStream` not in this list. – Vitali Plagov Jan 17 '17 at 19:11
  • Yes. I found only `java.io.ObjectOutputStream.PutField.write(ObjectOutput)` as deprecated. – Vüsal Jan 17 '17 at 19:28
  • `java.io.ObjectOutputStream` is *not* deprecated, and any tool that says otherwise is lying to you. – user207421 Aug 28 '20 at 02:37

1 Answers1

2

IntelliJ IDEA has an intention action to annotate library classes as Deprecated using the External Annotations support. You've probably triggered this intention action by accident.

annotate

For the classes deprecated this way there supposed to be the reverse action: Deannotate, but it may not work (bug reported).

To fix it manually, find the annotations.xml file in a directory that is configured in the SDK Annotations tab and edit/remove it.

UPDATE: Deannoate action should work now, but only while inside the annotated class itself, not from its reference.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904