Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 311432 - [rewrite] Inferred callouts to private static fields make OrganizeImports to import private fields
Summary: [rewrite] Inferred callouts to private static fields make OrganizeImports to ...
Status: VERIFIED FIXED
Alias: None
Product: Objectteams
Classification: Tools
Component: OTDT (show other bugs)
Version: 1.4   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 0.7 M2   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-03 16:45 EDT by Jan Marc Hoffmann CLA
Modified: 2011-05-10 09:08 EDT (History)
1 user (show)

See Also:
stephan.herrmann: iplog+


Attachments
test & fix (5.55 KB, patch)
2010-05-04 07:51 EDT, Stephan Herrmann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Marc Hoffmann CLA 2010-05-03 16:45:35 EDT
If inferred callouts are turned on, Organize Import will also try to import private static fields, which results in errors.
Comment 1 Stephan Herrmann CLA 2010-05-03 17:43:10 EDT
Would you have a simple example?

TIA
Comment 2 Jan Marc Hoffmann CLA 2010-05-04 06:15:27 EDT
Sure. :=)

Reproduce:

public team class SomeTeam {
	
	protected class SomeRole playedBy Base {
		
		m <-replace m;
		
		@SuppressWarnings({ "inferredcallout", "decapsulation" })
		callin void m(){
			boolean v = field;
			System.out.println(v);
		}
	}

}

Start Organize Imports.

Btw.: This does yield a more serious internal compiler error if used with "this" before the field. I ll file a new bug for this one.
Comment 3 Jan Marc Hoffmann CLA 2010-05-04 06:21:30 EDT
forgot the base:

public class Base {
	
	private static boolean field = true; 

	public void m(){
		
	}
}


(In reply to comment #2)
> Sure. :=)
> 
> Reproduce:
> 
> public team class SomeTeam {
> 
>     protected class SomeRole playedBy Base {
> 
>         m <-replace m;
> 
>         @SuppressWarnings({ "inferredcallout", "decapsulation" })
>         callin void m(){
>             boolean v = field;
>             System.out.println(v);
>         }
>     }
> 
> }
> 
> Start Organize Imports.
> 
> Btw.: This does yield a more serious internal compiler error if used with
> "this" before the field. I ll file a new bug for this one.
Comment 4 Stephan Herrmann CLA 2010-05-04 06:51:36 EDT
(In reply to comment #2)
Starting with your example I had to do the following:

- add a class b.Base (must not reside in the same package as SomeTeam)
  with this content:

  package b;
  public class Base {
	private static boolean field;
	void m() {}
  }

- organize imports once to correctly insert "import base b.Base;"
- organize imports once more to see the error.

The internal error I could not reproduce, so if you have instructions
how to do that it would be helpful.
Comment 5 Jan Marc Hoffmann CLA 2010-05-04 06:58:54 EDT
The internal Compiler Bug goes with the id: 311509

https://bugs.eclipse.org/bugs/show_bug.cgi?id=311509
Comment 6 Stephan Herrmann CLA 2010-05-04 07:51:19 EDT
Created attachment 166937 [details]
test & fix

Don't add a static import if
- a static field is not public AND
- it is accessed by a callout (which may apply decapsulation)
Comment 7 Stephan Herrmann CLA 2010-05-04 08:03:14 EDT
Patch has been committed as r292.
Comment 8 Stephan Herrmann CLA 2010-05-06 10:27:15 EDT
Verified for M2 using I201005052210
Comment 9 Stephan Herrmann CLA 2011-05-10 09:08:36 EDT
Setting iplog flag to acknowledge the contributed test case.