diff --git a/jOOQ-codegen/src/main/java/org/jooq/util/GenerationUtil.java b/jOOQ-codegen/src/main/java/org/jooq/util/GenerationUtil.java index f5ed699a9b..3468a60592 100644 --- a/jOOQ-codegen/src/main/java/org/jooq/util/GenerationUtil.java +++ b/jOOQ-codegen/src/main/java/org/jooq/util/GenerationUtil.java @@ -191,6 +191,32 @@ class GenerationUtil { ',' ))); + private static Set WINDOWS_FORBIDDEN = unmodifiableSet(new HashSet(asList( + "CON", + "PRN", + "AUX", + "CLOCK$", + "NUL", + "COM1", + "COM2", + "COM3", + "COM4", + "COM5", + "COM6", + "COM7", + "COM8", + "COM9", + "LPT1", + "LPT2", + "LPT3", + "LPT4", + "LPT5", + "LPT6", + "LPT7", + "LPT8", + "LPT9" + ))); + /** * Take a character and determine if it's a valid "Scala Letter" * http://www.scala-lang.org/files/archive/spec/2.11/01-lexical-syntax.html @@ -233,12 +259,25 @@ class GenerationUtil { * Letters, which include lower case letters (Ll), upper case letters (Lu), titlecase letters (Lt), other letters (Lo), letter numerals (Nl) and the two characters \u0024 ‘$’ and \u005F ‘_’, which both count as upper case letters. * * Character.isLetter handles the Ll, Lu, Lt, Lo, and Nl, supplement with _ and $ - * */ private static Boolean isScalaIdentifierPart(char c) { return isScalaIdentifierStart(c) || Character.isDigit(c); } + /** + * Take a name and escape it if it is a Windows forbidden name like + * CON or AUX. + * + * @see #5596 + */ + public static String escapeWindowsForbiddenNames(String name) { + return name == null + ? null + : WINDOWS_FORBIDDEN.contains(name.toUpperCase()) + ? name + "_" + : name; + } + /** * Take a literal (e.g. database column) and make it a Java identifier to be * used without case-change as an enum identifier diff --git a/jOOQ-codegen/src/main/java/org/jooq/util/GeneratorStrategyWrapper.java b/jOOQ-codegen/src/main/java/org/jooq/util/GeneratorStrategyWrapper.java index 290c102345..ec8341ec9f 100644 --- a/jOOQ-codegen/src/main/java/org/jooq/util/GeneratorStrategyWrapper.java +++ b/jOOQ-codegen/src/main/java/org/jooq/util/GeneratorStrategyWrapper.java @@ -41,6 +41,7 @@ package org.jooq.util; import static org.jooq.util.GenerationUtil.convertToIdentifier; +import static org.jooq.util.GenerationUtil.escapeWindowsForbiddenNames; import java.io.Serializable; import java.lang.reflect.Field; @@ -322,6 +323,7 @@ class GeneratorStrategyWrapper extends AbstractGeneratorStrategy { className = delegate.getJavaClassName(definition, mode); className = overload(definition, mode, className); className = convertToIdentifier(className, language); + className = escapeWindowsForbiddenNames(className); return className; } @@ -338,6 +340,7 @@ class GeneratorStrategyWrapper extends AbstractGeneratorStrategy { for (int i = 0; i < split.length; i++) { split[i] = convertToIdentifier(split[i], language); + split[i] = escapeWindowsForbiddenNames(split[i]); } return StringUtils.join(split, ".");