Skip to content

fix: Fix bugs and improve code quality across the codebase#233

Closed
Copilot wants to merge 3 commits intomasterfrom
copilot/optimize-project-code
Closed

fix: Fix bugs and improve code quality across the codebase#233
Copilot wants to merge 3 commits intomasterfrom
copilot/optimize-project-code

Conversation

Copy link
Contributor

Copilot AI commented Feb 28, 2026

Code audit fixing real bugs and cleaning up common anti-patterns.

Proposed Changes

Bug fixes

  1. Integer overflow in Cache.CACHE_HOLD_1DAY24 * 60 * 60 * 1000 * 1000 * 1000L overflows int before widening to long. Replaced all cache duration constants with TimeUnit.toNanos().
  2. Cache.get() parameter typed as String instead of generic K — broke contract of Cache<K, V>.
  3. DelayedItem.getDelay() no-op conversionunit.convert(delay, unit) converts unit→unit. Fixed to convert from TimeUnit.NANOSECONDS.
  4. DataBaseDocumentController ZIP entries all share same name — multi-format export produced corrupt ZIP. Now appends format-specific suffix.
  5. LogAspect.doAround() returns Map<String, Object> — unchecked cast fails for void/ModelAndView methods annotated with @Log. Changed to Object.

Code quality

  1. Replaced 16 e.printStackTrace() calls with SLF4J log.error(msg, e) across 7 files.
  2. SimpleCache constantsstaticstatic final.
  3. CacheManage.CACHE_MAP — eliminated raw types with proper generics.
  4. BaseUtils char case methods — replaced magic number arithmetic (chars[0] += 32, chars ^= 32) with Character.toLowerCase()/toUpperCase().
  5. BaseUtils.callbackNotFound — fixed javadoc that incorrectly said "深度克隆".
// Before: integer overflow (86,400,000,000 exceeds Integer.MAX_VALUE)
public static final long CACHE_HOLD_1DAY = 24 * 60 * 60 * 1000 * 1000 * 1000L;

// After: correct and readable
public static final long CACHE_HOLD_1DAY = TimeUnit.DAYS.toNanos(1);

Readiness Checklist

Author/Contributor

  • If documentation is needed for this change, has that been included in this pull request

Reviewing Maintainer

  • Label as either enhancement, bug, documentation, style or dependencies
  • Verify design and implementation

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • checkstyle.org
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/xml/tools/xml-extractor.jar --fileList=/tmp/codeql-scratch-e937359de4103e32/dbs/java/working/files-to-index5732281612012063206.list --sourceArchiveDir=/tmp/codeql-scratch-e937359de4103e32/dbs/java/src --outputDir=/tmp/codeql-scratch-e937359de4103e32/dbs/java/trap/java (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 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.

@naming-conventions-bot
Copy link

Thank you for following naming conventions! 😻

@mergify
Copy link

mergify bot commented Feb 28, 2026

Thanks for opening this pull request!
Please check out the Contributing Guidelines.

@mergify
Copy link

mergify bot commented Feb 28, 2026

@Copilot
Wrong PR Title: [WIP] Optimize and refactor project code for improvements
Please check Contributing Guidelines for more information.

- Fix integer overflow in Cache.CACHE_HOLD_1DAY (24*60*60*1000*1000*1000L overflows int)
- Fix Cache.get() to use generic type K instead of String
- Fix DelayedItem.getDelay() unit conversion (convert from NANOSECONDS, not unit)
- Fix ZIP entry duplicate name bug in DataBaseDocumentController
- Fix LogAspect.doAround() return type from Map to Object for void methods
- Replace e.printStackTrace() with SLF4J logging in 16 locations
- Make SimpleCache constants static final
- Fix incorrect javadoc on BaseUtils.callbackNotFound
- Fix raw types in CacheManage CACHE_MAP
- Replace magic numbers in BaseUtils char case methods with Character API

Co-authored-by: unknowIfGuestInDream <57802425+unknowIfGuestInDream@users.noreply.github.com>
@what-the-diff
Copy link

what-the-diff bot commented Feb 28, 2026

PR Summary

  • Enhancement to Logging Practices
    • Through updates to LogAspect.java and introduction of the SLF4J logger in BaseUtils.java, DataBaseInfoController.java, DataSourceUtilFactory.java, Cache.java, DataSourceUtil.java and FreeMarkerUtil.java, error handling will now be logged more efficiently, allowing for easier error tracking and resolution.
  • Refinements to Cache Management
    • In BaseUtils.java, the clarity of caching time definitions has been improved.
    • Through adjustments to CacheManage.java and CacheManageController.java, cache operations are now carried out consistently using parameterized types instead of raw types, leading to safer handling and less potential for errors.
    • The logic for cache key retrieval has been improved in the Cache.java file, thereby making the retrieval more efficient.
  • Updates to File Operations
    • In DataBaseDocumentController.java, zip entry naming has been adjusted to add the correct file suffix based on its engine type - this will make it easier for users to recognize the file type.
    • Optimizations have been made to string handling in SimpleCache.java, where variables have been replaced with constants for better performance and clarity.

…ull message in LogAspect

Co-authored-by: unknowIfGuestInDream <57802425+unknowIfGuestInDream@users.noreply.github.com>
@sonarqubecloud
Copy link

Copilot AI changed the title [WIP] Optimize and refactor project code for improvements Fix bugs and improve code quality across the codebase Feb 28, 2026
@github-actions github-actions bot added the enhancement New feature or request label Feb 28, 2026
@unknowIfGuestInDream unknowIfGuestInDream changed the title Fix bugs and improve code quality across the codebase fix: Fix bugs and improve code quality across the codebase Feb 28, 2026
@mergify mergify bot added the bug Something isn't working label Feb 28, 2026
@unknowIfGuestInDream unknowIfGuestInDream deleted the copilot/optimize-project-code branch February 28, 2026 05:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants