Skip to content

Commit f39a3b4

Browse files
springbootdemo-tomcat11: apply Gemini LOW findings from second review
Fixes from Gemini 2.5 Pro review of commit 82e6e24: - FinancialBenchmarkServiceTest: fix compilation error — resp.getInitialValue() does not exist on MonteCarloResponse; corrected to req.getInitialValue() (the redundant getInitialValue(req) helper has been removed as suggested) - FinancialBenchmarkServiceTest: use assertEquals(4L, ...) instead of assertTrue(... == 4, ...) for more informative failure messages - FinancialBenchmarkService: use SLF4J parameterized logging logger.warn("{} validation failed: {}", logPrefix, err) instead of string concatenation — avoids concatenation cost when WARN is disabled Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 29af789 commit f39a3b4

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

modules/samples/userguide/src/userguide/springbootdemo-tomcat11/src/main/java/userguide/springboot/webservices/FinancialBenchmarkService.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public PortfolioVarianceResponse portfolioVariance(PortfolioVarianceRequest requ
9595
int n = request.getNAssets();
9696
if (n <= 0 || n > MAX_ASSETS) {
9797
String err = "n_assets=" + n + " is out of range [1, " + MAX_ASSETS + "].";
98-
logger.warn(logPrefix + "validation failed: " + err);
98+
logger.warn("{} validation failed: {}", logPrefix, err);
9999
return PortfolioVarianceResponse.failed(err);
100100
}
101101

@@ -104,19 +104,19 @@ public PortfolioVarianceResponse portfolioVariance(PortfolioVarianceRequest requ
104104
if (cov == null) {
105105
String err = "Missing or malformed \"covarianceMatrix\": provide a " + n + "×" + n +
106106
" 2D array or a flat array of " + (long) n * n + " elements in row-major order.";
107-
logger.warn(logPrefix + "validation failed: " + err);
107+
logger.warn("{} validation failed: {}", logPrefix, err);
108108
return PortfolioVarianceResponse.failed(err);
109109
}
110110
if (cov.length != n) {
111111
String err = "covarianceMatrix row count " + cov.length + " != nAssets " + n + ".";
112-
logger.warn(logPrefix + "validation failed: " + err);
112+
logger.warn("{} validation failed: {}", logPrefix, err);
113113
return PortfolioVarianceResponse.failed(err);
114114
}
115115
for (int i = 0; i < n; i++) {
116116
if (cov[i] == null || cov[i].length != n) {
117117
String err = "covarianceMatrix row " + i + " has " +
118118
(cov[i] == null ? 0 : cov[i].length) + " columns, expected " + n + ".";
119-
logger.warn(logPrefix + "validation failed: " + err);
119+
logger.warn("{} validation failed: {}", logPrefix, err);
120120
return PortfolioVarianceResponse.failed(err);
121121
}
122122
}
@@ -131,7 +131,7 @@ public PortfolioVarianceResponse portfolioVariance(PortfolioVarianceRequest requ
131131
if (weightSum <= 0.0) {
132132
String err = "normalizeWeights=true but weights sum to " + weightSum +
133133
". Cannot normalize a zero-weight portfolio.";
134-
logger.warn(logPrefix + "validation failed: " + err);
134+
logger.warn("{} validation failed: {}", logPrefix, err);
135135
return PortfolioVarianceResponse.failed(err);
136136
}
137137
if (Math.abs(weightSum - 1.0) > 1e-10) {
@@ -144,7 +144,7 @@ public PortfolioVarianceResponse portfolioVariance(PortfolioVarianceRequest requ
144144
String err = "weights sum to " + String.format("%.8f", weightSum) +
145145
", expected 1.0 (tolerance 1e-4). " +
146146
"Pass normalizeWeights=true to rescale automatically.";
147-
logger.warn(logPrefix + "validation failed: " + err);
147+
logger.warn("{} validation failed: {}", logPrefix, err);
148148
return PortfolioVarianceResponse.failed(err);
149149
}
150150
}
@@ -346,7 +346,7 @@ public ScenarioAnalysisResponse scenarioAnalysis(ScenarioAnalysisRequest request
346346
int nAssets = assets.size();
347347
if (nAssets > MAX_ASSETS) {
348348
String err = "assets count " + nAssets + " exceeds maximum " + MAX_ASSETS + ".";
349-
logger.warn(logPrefix + "validation failed: " + err);
349+
logger.warn("{} validation failed: {}", logPrefix, err);
350350
return ScenarioAnalysisResponse.failed(err);
351351
}
352352

@@ -369,7 +369,7 @@ public ScenarioAnalysisResponse scenarioAnalysis(ScenarioAnalysisRequest request
369369
"Pass probTolerance to adjust validation strictness.",
370370
i, asset.getAssetId(), probSum, probTolerance,
371371
asset.getScenarios().size());
372-
logger.warn(logPrefix + "validation failed: " + err);
372+
logger.warn("{} validation failed: {}", logPrefix, err);
373373
return ScenarioAnalysisResponse.failed(err);
374374
}
375375
}

modules/samples/userguide/src/userguide/springbootdemo-tomcat11/src/test/java/userguide/springboot/webservices/FinancialBenchmarkServiceTest.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void testPortfolioVariance_twoAssets_knownResult() {
6767
"annualized volatility uses nPeriodsPerYear=252 by default");
6868
assertEquals(1.0, resp.getWeightSum(), 1e-10, "weight_sum should be 1.0");
6969
assertFalse(resp.isWeightsNormalized(), "weights should not be normalized when already summing to 1.0");
70-
assertTrue(resp.getMatrixOperations() == 4, "2x2 matrix = 4 operations");
70+
assertEquals(4L, resp.getMatrixOperations(), "2x2 matrix = 4 operations");
7171
}
7272

7373
@Test
@@ -253,7 +253,7 @@ void testMonteCarlo_zeroVolatility_allPathsEqual() {
253253

254254
assertEquals("SUCCESS", resp.getStatus());
255255
// With zero drift and zero volatility, all paths end at initialValue
256-
assertEquals(resp.getInitialValue(), resp.getMeanFinalValue(), 1.0,
256+
assertEquals(req.getInitialValue(), resp.getMeanFinalValue(), 1.0,
257257
"zero vol, zero drift: mean should equal initialValue");
258258
}
259259

@@ -521,8 +521,4 @@ private ScenarioAnalysisRequest.AssetScenario buildSimpleAsset(
521521
return asset;
522522
}
523523

524-
/** Expose initialValue for test assertions (not in response, but useful here). */
525-
private double getInitialValue(MonteCarloRequest req) {
526-
return req.getInitialValue();
527-
}
528524
}

0 commit comments

Comments
 (0)