GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix Root class name conflict in JDOM writer generator by Copilot · Pull Request #520 · codehaus-plexus/modello

Conversation

Copilot AI commented Oct 5, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Problem

When using Root as a class name for the root element in a model definition, the JDOM writer generator would produce code that failed to compile due to a variable naming conflict.

The generated updateRoot() method would declare both:

  • A parameter Root root (from uncapitalizing the class name "Root")
  • A local variable Element root (for the XML element being created)

This resulted in a compilation error:

variable root is already defined in method updateRoot(org.example.Root,java.lang.String,Counter,Document)

Solution

Renamed the local Element variable from root to rootElement throughout the JDOMWriterGenerator.updateClass() method. This makes the generated code use distinct names:

  • root - the model object parameter
  • rootElement - the XML Element being created

Before (would not compile):

protected void updateRoot(Root root, String xmlTag, Counter counter, Document document) {
    if (root != null) {
        Element root = factory.element(xmlTag, "..."); // ❌ Conflict!
        root.getName(); // Which 'root' is this?
    }
}

After (compiles successfully):

protected void updateRoot(Root root, String xmlTag, Counter counter, Document document) {
    if (root != null) {
        Element rootElement = factory.element(xmlTag, "..."); // ✅ Clear distinction
        updateElement(innerCount, rootElement, "name").setText(root.getName()); // ✅ No ambiguity
    }
}

Testing

  • Added root-classname.mdo test model with Root as the class name
  • Added RootClassnameJDOMGeneratorTest to verify generated code compiles successfully
  • All existing JDOM plugin tests continue to pass
  • Verified the fix works with both namespace and non-namespace configurations

Fixes the issue where models with a root class named "Root" would generate non-compilable JDOM writer code.

Original prompt

This section details on the original issue you should resolve

<issue_title>Root can not be used as class name for jdom-writer</issue_title>
<issue_description>To reproduce:

  <classes>
    <class rootElement="true">
      <name>Root</name>
      <version>1.0.0+</version>
       ...
    </class>
  <classes>

Local field as root is used in code and conflict with generated code.
</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #404

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Copilot AI assigned Copilot and slachiewicz Oct 5, 2025
Copilot AI changed the title [WIP] Root can not be used as class name for jdom-writer Fix Root class name conflict in JDOM writer generator Oct 5, 2025
Copilot AI requested a review from slachiewicz October 5, 2025 17:53
@slachiewicz
slachiewicz marked this pull request as ready for review October 5, 2025 19:13
@slachiewicz
slachiewicz requested a review from slawekjaranowski October 5, 2025 19:18
slachiewicz
slachiewicz approved these changes Oct 6, 2025
View reviewed changes
Copilot AI and others added 3 commits October 7, 2025 20:26
@slachiewicz
Fix Root class name conflict in JDOM writer by renaming local variabl…
1b391d1
…e to rootElement

Co-authored-by: slachiewicz <[email protected]>
@slachiewicz
Add test case for Root class name in JDOM writer
476e45f
Co-authored-by: slachiewicz <[email protected]>
@slachiewicz
Revert "Root" root element
890036f
@slachiewicz
slachiewicz force-pushed the copilot/fix-353cdf2f-318b-4b0a-8d37-112db8f32f4e branch from 5ddb79a to 890036f Compare October 7, 2025 18:31
@slachiewicz
slachiewicz merged commit bca1253 into master Oct 8, 2025
@slachiewicz
slachiewicz deleted the copilot/fix-353cdf2f-318b-4b0a-8d37-112db8f32f4e branch October 8, 2025 16:16
@slachiewicz slachiewicz added the bug Something isn't working label Nov 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@slawekjaranowski slawekjaranowski Awaiting requested review from slawekjaranowski
1 more reviewer
@slachiewicz slachiewicz slachiewicz approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@slachiewicz slachiewicz

Copilot code review Copilot

Labels

bug Something isn't working

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Root can not be used as class name for jdom-writer

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@slachiewicz
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.