Commit efeb2d2
fix: reduce deep nesting from 83 to 51 statements through method extraction
Reduces deeply nested statements by 39% (from 83 to 51) by:
1. Extract nesting reduction in ClassLoaderCleanupUtil:
- Split clearThreadLocals() into 5 focused methods to reduce nesting
- Extract cleanupThreadLocalsForMatchingThreads() to eliminate nested if-statements
- clearThreadLocalTable(), clearThreadLocalTableEntries(), clearThreadLocalEntryIfNeeded()
all reduce nesting through early returns and guard clauses
2. Refactor AuthHelper to eliminate nested validation:
- Extract configureBasicAuth() and configureBearerAuth() private methods
- Use switch statement to dispatch instead of nesting validation inside switch cases
3. Extract JAR handling in NexusClassSource:
- Create findAndExtractClassFromJar() to eliminate nested while loops
- Create extractClassDataFromJarEntry() to handle inner loop and size validation
4. Simplify RetryPolicy retry logic:
- Extract performBackoffDelay() method to reduce nesting in execute()
- Use early continue with inverted guard clause
5. Apply guard clause in DatabaseClassSource:
- Replace if-then-else with guard clause (early throw) to reduce nesting
Impact:
- Deep nesting statements reduced from 83 to 51 (39% improvement)
- Cyclomatic complexity reduced through smaller, focused methods
- Code maintainability and testability improved
- Methods now follow single responsibility principle
Fixes issue #251
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent 58db5ee commit efeb2d2
15 files changed
Lines changed: 741 additions & 398 deletions
File tree
- src/main/java/org/flossware/classloader
- filesystem
- jar
- rest
- util
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
| 27 | + | |
35 | 28 | | |
36 | 29 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 30 | + | |
42 | 31 | | |
43 | 32 | | |
44 | 33 | | |
45 | 34 | | |
46 | 35 | | |
47 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
48 | 56 | | |
Lines changed: 2 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
105 | | - | |
106 | | - | |
| 104 | + | |
107 | 105 | | |
108 | 106 | | |
| 107 | + | |
109 | 108 | | |
110 | 109 | | |
111 | 110 | | |
| |||
0 commit comments