This is an automated email from the ASF dual-hosted git repository.
rmaucher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat-jakartaee-migration.git
The following commit(s) were added to refs/heads/main by this push:
new db341f7 Properly reconstruct the original pool
db341f7 is described below
commit db341f74bb14b6159e83c13e71b601189b027941
Author: remm <[email protected]>
AuthorDate: Fri Jun 5 16:53:57 2026 +0200
Properly reconstruct the original pool
Code review gave some examples of replace with common prefixes possibly
causing issues. My old code was producing "ok" results, but it is better
to replace it.
Instead, try to properly reconstruct the pool.
Co authored using OpenCode.
---
CHANGES.md | 3 ++
.../apache/tomcat/jakartaee/ClassConverter.java | 34 ++++++++++++----------
2 files changed, 21 insertions(+), 16 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index 1f19192..21785d1 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,5 +1,8 @@
# Tomcat Migration Tool for Jakarta EE - Changelog
+## 1.0.13
+- Properly reconstruct the original pool in the ClassConverter transformer if
a class is found to be available. (remm)
+
## 1.0.12
- Add Maven Wrapper Plugin to manage the Maven wrapper. (markt)
- Update the Maven Wrapper and switch to 'only-script' configuration. (markt)
diff --git a/src/main/java/org/apache/tomcat/jakartaee/ClassConverter.java
b/src/main/java/org/apache/tomcat/jakartaee/ClassConverter.java
index 46e1a02..8267dbc 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/ClassConverter.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/ClassConverter.java
@@ -129,18 +129,23 @@ public class ClassConverter implements Converter,
ClassFileTransformer {
// Object comparison is deliberate
if (newString != str) {
if (loader != null) {
- // Since this is a runtime conversion, the idea is to
only convert to
- // Jakarta EE specification classes that exist in the
container
- String[] split = newString.split(";|<");
- for (String current : split) {
- int pos = current.indexOf(profile.getTarget() +
"/");
+ // Only convert to Jakarta EE classes that actually
exist in the
+ // container. Build the result by processing each
fragment
+ // independently so we never need to revert a
conversion.
+ String[] convertedFragments = newString.split(";|<",
-1);
+ String[] originalFragments = str.split(";|<", -1);
+ StringBuilder result = new StringBuilder();
+ for (int fi = 0; fi < convertedFragments.length; fi++)
{
+ String convertedFragment = convertedFragments[fi];
+ String originalFragment = originalFragments[fi];
+ int pos =
convertedFragment.indexOf(profile.getTarget() + "/");
boolean dotMode = false;
if (pos < 0) {
- pos = current.indexOf(profile.getTarget() +
".");
+ pos =
convertedFragment.indexOf(profile.getTarget() + ".");
dotMode = true;
}
if (pos >= 0) {
- String resourceName = current.substring(pos);
+ String resourceName =
convertedFragment.substring(pos);
if (dotMode) {
resourceName = resourceName.replace('.',
'/');
}
@@ -149,19 +154,16 @@ public class ClassConverter implements Converter,
ClassFileTransformer {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE,
sm.getString("classConverter.skipName",
profile.getSource(),
-
current.substring(pos).replace('/','.')));
+
convertedFragment.substring(pos).replace('/','.')));
}
- // Cancel the replacement as the
replacement does not exist
- String originalFragment;
- if (dotMode) {
- originalFragment =
current.replace(profile.getTarget() + ".", profile.getSource() + ".");
- } else {
- originalFragment =
current.replace(profile.getTarget() + "/", profile.getSource() + "/");
- }
- newString = newString.replace(current,
originalFragment);
+ // Use the original (unconverted) fragment
+ result.append(originalFragment);
+ continue;
}
}
+ result.append(convertedFragment);
}
+ newString = result.toString();
}
c = new ConstantUtf8(newString);
constantPool[i] = c;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]