fix: freemarker 生成错误#210
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (2)
📝 WalkthroughWalkthrough更新 Freemarker 配置与模板:在代码中将 DefaultObjectWrapperBuilder 的版本来源改为 Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/service/impl/GeneratorServiceImpl.java`:
- Line 312: 当前在构造 DefaultObjectWrapper 时使用了 Configuration.getVersion()(见
DefaultObjectWrapperBuilder 的构造调用),这会随运行时 FreeMarker 版本变化带来不确定行为;请改为使用固定的
FreeMarker 版本常量(例如 Configuration.VERSION_2_3_33 或项目实际使用的常量)作为
DefaultObjectWrapperBuilder 的构造参数,以保证向后兼容性并避免运行时行为改变。
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 79f18654-5e8f-48e7-be88-07a66e34cc92
📒 Files selected for processing (2)
continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/service/impl/GeneratorServiceImpl.javacontinew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Menu.ftl
| // 在模板中允许使用静态方法 | ||
| if (engine instanceof FreemarkerEngine freemarkerEngine) { | ||
| DefaultObjectWrapper wrapper = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_33).build(); | ||
| DefaultObjectWrapper wrapper = new DefaultObjectWrapperBuilder(Configuration.getVersion()).build(); |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# 检查项目中 FreeMarker 的版本和 Configuration 类的方法
echo "=== 查找 FreeMarker 依赖版本 ==="
fd -e xml -e gradle 'pom.xml|build.gradle' --exec rg -A2 -B2 'freemarker'
echo -e "\n=== 查找 Configuration 类的使用情况 ==="
rg -n "Configuration\.(getVersion|VERSION_)" --type java -C2Repository: continew-org/continew-admin
Length of output: 1260
🌐 Web query:
FreeMarker Configuration.getVersion() static method API documentation
💡 Result:
Yes, FreeMarker has a static method Configuration.getVersion that returns the Version object representing the FreeMarker version (major.minor.micro numbers and qualifiers). It is documented in the official FreeMarker 2.3.34 JavaDoc. Signature: public static Version getVersion Description: Returns FreeMarker version information, most importantly the major.minor.micro version numbers. Do NOT use this as the value of the incompatible_improvements setting (as the parameter to Configuration(Version)), as then your application can break when you upgrade FreeMarker! Use a constant value, like VERSION_2_3_34, to protect your application from fixes/changes that aren't entirely backward compatible. This method has been present since at least FreeMarker 2.3.20, and is available in the latest version 2.3.34 (as of 2026-04-03). Official documentation: https://freemarker.apache.org/docs/api/freemarker/template/Configuration.html#getVersion Note: There is also a deprecated getVersionNumber that returns a String.
Citations:
- 1: https://freemarker.apache.org/docs/api/freemarker/template/Configuration.html
- 2: https://freemarker.apache.org/docs/api/freemarker/template/Version.html
- 3: https://freemarker.sourceforge.io/docs/api/freemarker/template/Configuration.html
使用 FreeMarker 的静态常量而非 Configuration.getVersion()
Configuration.getVersion() 是有效的静态方法,但根据 FreeMarker 官方文档,不应该将其用作 incompatible_improvements 设置的值(即 DefaultObjectWrapperBuilder 的构造参数)。当 FreeMarker 版本升级时,使用运行时版本号会导致应用行为改变。
建议改为使用固定的版本常量,如 Configuration.VERSION_2_3_33 或对应项目实际使用的 FreeMarker 版本常量,以保护应用免受非完全向后兼容的改变影响。
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/service/impl/GeneratorServiceImpl.java`
at line 312, 当前在构造 DefaultObjectWrapper 时使用了 Configuration.getVersion()(见
DefaultObjectWrapperBuilder 的构造调用),这会随运行时 FreeMarker 版本变化带来不确定行为;请改为使用固定的
FreeMarker 版本常量(例如 Configuration.VERSION_2_3_33 或项目实际使用的常量)作为
DefaultObjectWrapperBuilder 的构造参数,以保证向后兼容性并避免运行时行为改变。
PR 类型
PR 目的
解决方案
PR 测试
Changelog
其他信息
提交前确认
Summary by CodeRabbit
发布说明