Triggered by this bug report AVRO-1814 I reduced the problem to this minimal example case in Java that simply shows the core of the effect.
package nl.basjes.experiment;
public class NamingClash {
String nl = "foo";
public void test() {
nl.basjes.experiment.NamingClash.foo();
}
private static void foo() {
// Do something
}
}
Trying to compile this will give you
error: cannot find symbol
nl.basjes.experiment.NamingClash.foo();
^
symbol: variable basjes
location: variable nl of type String
In AVRO the code is generated and it must try to avoid name collisions under the assumption people will sometimes choose unexpected names.
So assume in this example that
- The fully qualified class name in the 'test()' method is needed to avoid a collision.
- The variable 'nl' is just the name used in the schema definition.
- Generating a field like _nl__ and have getters and setters would be a change that will break backwards compatibility because the nl field has always been public.
Other than telling people "Just don't do that".
Is there a solution to avoid these conflicts?
Note that for the AVRO bug that triggered this question I found a workaround. Here I'm looking for the 'generic answer'.