Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 380065

Summary: [quick fix] for a non-static (field) initializer throwing an exception
Product: [Eclipse Project] JDT Reporter: Rudolf Schmidt <mail>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: markus.kell.r
Version: 3.8   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard: stalebug

Description Rudolf Schmidt CLA 2012-05-19 17:14:37 EDT
Build Identifier: 3.7.2


eclipse is the best quickfix offering ide i have gotten to know. for all other situations eclipse offers an eclipse handling quickfix like surrounding with try-catch or add a "throw" to a the operation signature or to the constructor. so it is inconsistency to keep no quickfix handling for that situation.

Reproducible: Always

Steps to Reproduce:
1. creating a class with following code

import java.net.Socket;
public class ConnectionClass {

	Socket socket = new Socket("", 6667);
}

you will notice that you will get a compiling error with following hint: "Default constructor cannot handle exception type IOException thrown by implicit super constructor. Must define an explicit constructor"

if you already wrote a constructor like

import java.net.Socket;
public class ConnectionClass {

	Socket socket = new Socket("", 6667);
	
	public ConnectionClass() {}
}

you will get an other hint instead of the above: "Unhandled exception type IOException"
Comment 1 Markus Keller CLA 2012-05-21 09:27:02 EDT
Yes, we should have a quick fix for non-static (field) initializers that throw an exception. Quick fix is also missing here:
    {
        Socket socket = new Socket("", 6667);
    }

The quick fix should add a default constructor if there's none, or it should add the exception to all existing constructors.
Comment 2 Eclipse Genie CLA 2020-05-16 11:56:42 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.