projectlombok/lombok · error · IllegalArgumentException

Invalid identifier

Error message

Invalid identifier ${trimmedName}

What it means

IdentifierName.valueOf validates that a configuration value is a valid Java identifier (via JavaIdentifiers.isValidJavaIdentifier) before wrapping it. Blank values return null, but any non-identifier text throws IllegalArgumentException.

Solutions

  1. Provide a single valid Java identifier (letters, digits, _, $; not starting with a digit; not a keyword).
  2. Remove package qualifiers or extra characters (dots, dashes, spaces).
  3. If the key expects a type, use the configuration key that accepts a TypeName instead.

Example fix

// before (lombok.config)
lombok.someIdentifierKey = my.field.Name
// after
lombok.someIdentifierKey = Name
Defensive patterns

Strategy: validation

Validate before calling

boolean isValidIdentifierName(String name) {
  return name != null && !name.trim().isEmpty() && javax.lang.model.SourceVersion.isName(name.trim());
}

Try / catch

try {
  IdentifierName id = IdentifierName.valueOf(raw);
} catch (IllegalArgumentException e) {
  // reject config value or fall back to default identifier
}

Prevention

When it happens

Trigger: Calling IdentifierName.valueOf(String) with a trimmed string that is not a valid Java identifier — e.g. starts with a digit, contains dots, spaces, hyphens, or reserved characters.

Common situations: Using a fully qualified name (with dots) where only a simple identifier is allowed, typo'd field/method names like 'my-field' or '2fa' in lombok.config keys that expect an identifier.

Related errors


AI-assisted analysis of projectlombok/lombok@6d6a3e9fec (2026-09-07). Data as JSON: /api/errors/831e5c847bd8f1b2. Report an issue: GitHub.

Appendix: source

Thrown at src/core/lombok/core/configuration/IdentifierName.java:37

 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package lombok.core.configuration;

import lombok.core.JavaIdentifiers;

public final class IdentifierName implements ConfigurationValueType {
	private final String name;
	
	private IdentifierName(String name) {
		this.name = name;
	}
	
	public static IdentifierName valueOf(String name) {
		if (name == null || name.trim().isEmpty()) return null;
		
		String trimmedName = name.trim();
		if (!JavaIdentifiers.isValidJavaIdentifier(trimmedName)) throw new IllegalArgumentException("Invalid identifier " + trimmedName);
		return new IdentifierName(trimmedName);
	}
	
	public static String description() {
		return "identifier-name";
	}
	
	public static String exampleValue() {
		return "<javaIdentifier>";
	}
	
	@Override public boolean equals(Object obj) {
		if (!(obj instanceof IdentifierName)) return false;
		return name.equals(((IdentifierName) obj).name);
	}
	
	@Override public int hashCode() {
		return name.hashCode();

View on GitHub (pinned to 6d6a3e9fec)