realm-java icon indicating copy to clipboard operation
realm-java copied to clipboard

Improve error-message for duplicate models "attempt to recreate a file for type io.realm.<GeneratedProxyClass>"

Open dotgc opened this issue 11 years ago • 8 comments

I get this erorr while building the project.

dotgc avatar Dec 22 '14 19:12 dotgc

Can you please detail what you attempt, detailed log and how you have tried to debug it? Thanks

bmunkholm avatar Dec 22 '14 20:12 bmunkholm

I created a model class by extending the RealmObject class. While building the project I get the error

Error:(8, 8) error: Attempt to recreate a file for type io.realm.NotificationModelRealmProxy
Note: Processing class UserModel
Note: Version 0.76.0 of Realm is now available: http://static.realm.io/downloads/java/latest

dotgc avatar Dec 22 '14 20:12 dotgc

Nevermind. Got it.

dotgc avatar Dec 22 '14 20:12 dotgc

I had another model class with the same name in another package.

dotgc avatar Dec 22 '14 20:12 dotgc

Happy you got it solved. I'll change the title into an enhancement suggestion. Maybe we could make that error message more clear.

bmunkholm avatar Dec 23 '14 07:12 bmunkholm

A check for existing classes with the same name should be added here: https://github.com/realm/realm-java/blob/master/realm/realm-annotations-processor/src/main/java/io/realm/processor/RealmProcessor.java#L172 and an appropriate error thrown

cmelchior avatar Jan 30 '17 08:01 cmelchior

In my case, this was caused because IntelliJ generates sources to out while Gradle generates it to build. However, IntelliJ then marked Gradle's generated sources folder as "source folder". So when compiling, it now ended up having those sources twice.

I haven't investigated yet why this happens and how to avoid it, but a quick fix is to delete the generated sources in the build directory.

micheljung avatar May 27 '19 05:05 micheljung

This should have been fixed. Model classes are embedding the package name as part of the name for the class, so no collisions should be possible unless it would also crash the Java compiler.

cmelchior avatar Nov 27 '19 15:11 cmelchior