Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ private List<GeneratePreviewResp> preview(String tableName) {
.createEngine(new TemplateConfig("templates", TemplateConfig.ResourceMode.CLASSPATH));
// 在模板中允许使用静态方法
if (engine instanceof FreemarkerEngine freemarkerEngine) {
DefaultObjectWrapper wrapper = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_33).build();
DefaultObjectWrapper wrapper = new DefaultObjectWrapperBuilder(Configuration.getVersion()).build();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 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 -C2

Repository: 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:


使用 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 的构造参数,以保证向后兼容性并避免运行时行为改变。

freemarkerEngine.getConfiguration().setSharedVariable("statics", wrapper.getStaticModels());
}
for (Map.Entry<String, GeneratorProperties.TemplateConfig> templateConfigEntry : templateConfigMap.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<#setting number_format="#">
SET @parentId = ${statics["cn.hutool.core.util.IdUtil"].getSnowflakeNextId()?c};
-- ${businessName}管理菜单
INSERT INTO `sys_menu`
Expand Down
Loading