Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator produces an invalid enum with an underscore "_" as the name #10866

Closed
nyoungac opened this issue Nov 5, 2020 · 8 comments
Closed

Comments

@nyoungac
Copy link

nyoungac commented Nov 5, 2020

Using the 3.14.1 code generator with Java on a MySQL database with an enum field defined as:

  `t_offset_o` enum('-','+') NOT NULL DEFAULT '+',

OR

  `ref` enum('', <...>) NOT NULL DEFAULT '',

produce an invalid underscore "_" enum:

_(""),

expected: Have some placeholder or random name.

@lukaseder
Copy link
Member

Thanks for your report. As a workaround, you can always implement a generator strategy to assign different identifiers to your enums: https://www.jooq.org/doc/latest/manual/code-generation/codegen-generatorstrategy/

@lukaseder
Copy link
Member

This seems to be an oversight in the fix for #4703.

@lukaseder
Copy link
Member

Hmm, no. Unfortunately, generator strategies aren't involved in generating the identifiers for enum literals. That might be another issue: #10881

Your examples show an interesting case. While it would be possible to disambiguate the _ characters individually, if you had created an enum like this, we'd get yet another issue where disambiguated identifiers create a conflict, because they're both the same:

enum ('', '-')

I don't want to rush fixing this. It seems that name disambiguation could use some more thorough thought...

@lukaseder
Copy link
Member

Another workaround is to use a CHECK (t_offset_o IN ('-', '+')) constraint, and make it CHAR(1) instead of ENUM

@berndwaibel
Copy link

berndwaibel commented Jan 20, 2021

Same Problem here: MySQL, Enum Type:
enum('store','single','multiple','sold','')
The "" string does produce an underscore.

This is a very bad problem, as this is no more supported in JDK > 9.
So the created code (created by Jooq 3.14.4) will not compile if the JDK Level is 9 or above

Warning in JDK 8:
error: as of release 9, '_' is a keyword, and may not be used as an identifier _(""),

As this is a "does not compile" error, is it possible to put the priority a little bit higher than medium?

@lukaseder
Copy link
Member

Starting from jOOQ 3.16, such problems can be worked around using a GeneratorStrategy configuration: #10881

We should obviously never generate _ enum literals, but at least there will be a workaround until this is fixed.

@lukaseder
Copy link
Member

I'm fixing this particular issue here, where enum literals can be produced by the name _. For now, they just generate __. It seems that the fix from #4703 wasn't applied to enum literals.

There's still more name mangling to be done, but it might be more edge-casey than this one (?): #12732

Again, at least with 3.16, the GeneratorStrategy now supports overriding the default behaviour for enum literals as well via #10881.

@lukaseder
Copy link
Member

Fixed in jOOQ 3.16. I won't backport this fix, because it could break existing generated code elsewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants