apache/fory

[Java] CodegenException: Compile error if class has a field named `buffer`

Closed this issue · 1 comments

Search before asking

  • I had searched in the issues and found no similar issues.

Version

0.12.1

Component(s)

Java

Minimal reproduce step

When java class has a field named buffer and codegen is triggered org.apache.fory.codegen.CodegenException happens.

What did you expect to see?

No exception

What did you see instead?

The reason is the write method where the folowing code is generated:

/* 0054 */   @Override public final void write(MemoryBuffer buffer, Object obj) {
/* 0055 */       SomeClass someClass = (SomeClass)obj;
/* 0056 */       Object object1 = Platform.getObject(someClass, 12L);
/* 0057 */       FieldType buffer = (FieldType) object1;
/* 0058 */       if ((!refResolver.writeRefOrNull(buffer, buffer))) {
/* 0059 */           this.writeClassAndObject(buffer, buffer);
/* 0060 */       }
/* 0061 */   }

note that both argument for MemoryBuffer and variable for field are named buffer

Anything Else?

The reason seems to be BaseObjectCodecBuilder where public static final String BUFFER_NAME = "buffer"; hardcodes variable name.

I'd like to provide small project as repro, but it's not clear to me when this codegen is triggered. If I can manage to reproduce this I might be able to submit PR with a fix

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Should be Fixed in #2565