Harsh Gupta Harsh Gupta - 1 year ago 86
Java Question

Refactoring a Java project causes hundreds of "X not public" errors

I'm busy upgrading an ancient java app, and after getting it compiling I set about reorganizing the code structure. There are currently 500 files in ONE massive folder, so I need to split it into a neater folder structure. The moment I moved some files, the compiler generates heaps of

"X() is not public in <BaseClass>"
errors. Yes, the refactoring tool added package statements and imports to both sides,

Apparently every class has all its members with implicit visibility, ie:

void setSelection(int x){...}

Apart from manually adding visibility attributes, is there a faster way to resolve the mess with less editing?

public void setSelection(int x){...} /// Yay! only 5000 more occurrences to go!

Answer Source

I think you should fix this by hand. For each class and class member make a judgment as to whether the access should be public, protected, private or package private. Creating / fixing modularity and abstraction boundaries is not something that I would trust to a dumb tool.

Yes, if you have hundreds of error message, you have lots of things to correct. But the end result will be better quality code ... than if you blindly changed all package private to stuff to public.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download