Skip to content

New Spring Starter Project wizard shows "-1" instead of "demo" as default project name #1927

Description

@cypher256

Summary

Opening the "New Spring Starter Project" wizard sometimes pre-fills the Name and Artifact fields with the literal string -1 instead of a sensible non-empty default such as demo.

This is reproducible without any UI interaction by instantiating NewSpringBootWizardModel directly.

Root cause

Two independent gaps combine to produce this:

1. NewSpringBootWizardModel#discoverOptions only null-checks the default value fetched from the Initializr metadata service:

String defaultValue = textInputs.get(name);
if (defaultValue!=null) {
fields.add(new StringFieldModel(name, defaultValue).label(e.getValue()));
}

String defaultValue = textInputs.get(name);
if (defaultValue!=null) {
    fields.add(new StringFieldModel(name, defaultValue).label(e.getValue()));
}

If the Initializr service ever returns an empty string (not null) as the default for the name field, this check passes it straight through, so the name field's LiveVariable starts out as "" instead of a sane fallback like demo.

2. NameGenerator has no guard against an empty prefix:

https://github.com/spring-projects/spring-tools/blob/46a3b356d75d4575c0345bdaf046ae37e3cb1510/eclipse-language-servers/org.springsource.ide.eclipse.commons.core/src/org/springsource/ide/eclipse/commons/core/util/NameGenerator.java

public NameGenerator(String previousName) {
    prefix = previousName.replace(' ', '-');
    ...
}

public String generateNext() {
    StringBuilder sb = new StringBuilder();
    sb.append(prefix);
    sb.append(delimiter);   // "-"
    sb.append(++number);    // 1
    return sb.toString();
}

NewProjectNameValidator correctly flags an empty project name as invalid ("Project name is empty"), which makes NewSpringBootWizardModel#generateValidProjectName() call new NameGenerator(projectName.getValue()) to "fix" it:

private void generateValidProjectName() {
boolean projectNameValid = projectName.getValidator().getValue() == ValidationResult.OK;
if (!projectNameValid) {
NameGenerator generator = new NameGenerator(projectName.getValue());
int limit = 5; //See: https://github.com/spring-projects/spring-ide/issues/230
while (!projectNameValid && limit-- > 0) {
projectName.setValue(generator.generateNext());
projectNameValid = projectName.getValidator().getValue() == ValidationResult.OK;
}
}
}

With an empty input, prefix ends up "", and generateNext() returns "" + "-" + "1" = -1 — a value that looks like a plausible auto-incremented name but is actually meaningless, and is itself accepted as valid by the name validator (no leading-character restriction), so the loop stops immediately and the UI shows -1 as if it were normal.

Reproduction (headless, no UI)

Instantiating the model directly and reading the name field reproduces the issue deterministically:

NewSpringBootWizardModel model = new NewSpringBootWizardModel();
FieldModel<String> nameField = model.stringInputs.getField("name");
System.out.println(nameField.getValue()); // prints "-1"

Suggested fix

  • In discoverOptions, treat a blank string the same as null (e.g. if (defaultValue != null && !defaultValue.isBlank())) so a field never starts out empty when a fallback default is more appropriate.
  • In NameGenerator, fall back to a non-empty prefix (e.g. "project" or reject empty input) so it can never emit a name consisting of only a delimiter and a number.

Either fix alone would prevent the -1 from ever reaching the UI.

Environment

  • org.springframework.ide.eclipse.boot.wizard 5.2.0.202606090740 (Eclipse 2026-06 based product)
  • Also present in main as of commit 46a3b35 (both files unchanged since 2020/2022 respectively)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions