Skip to content

Commit d42fe21

Browse files
author
alpsla
committed
rex(#4): Create Live Test Fixture - Java
1 parent 18063e5 commit d42fe21

3 files changed

Lines changed: 253 additions & 4 deletions

File tree

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
/**
2+
* Live Test Java File for Tier 2 Native Fixer Validation
3+
*
4+
* This file contains INTENTIONAL issues that should be fixed by various tiers:
5+
*
6+
* Tier 1 (google-java-format):
7+
* - Inconsistent indentation
8+
* - Missing/extra whitespace
9+
* - Brace placement
10+
* - Import formatting
11+
*
12+
* Tier 2 (Sorald):
13+
* - S1155: Use isEmpty() instead of size() == 0
14+
* - S2095: Resources should be closed (try-with-resources)
15+
* - S1132: String literals should be on the left side of equals()
16+
*
17+
* Tier 3 (AI Required - PMD rules):
18+
* - UselessParentheses: Remove unnecessary parentheses
19+
* - AvoidDollarSigns: Identifier names should not contain dollar signs
20+
* - CloseResource: Ensure resources are properly closed
21+
* - EmptyCatchBlock: Empty catch blocks should have comment or handling
22+
*
23+
* DO NOT manually fix these issues - they are test fixtures.
24+
*/
25+
package com.codequal.fixtures;
26+
27+
import java.io.BufferedReader;
28+
import java.io.File;
29+
import java.io.FileInputStream;
30+
import java.io.FileReader;
31+
import java.io.IOException;
32+
import java.io.InputStream;
33+
import java.util.ArrayList;
34+
import java.util.HashMap;
35+
import java.util.List;
36+
import java.util.Map;
37+
38+
public class TestClass {
39+
40+
// Tier 3 (PMD): AvoidDollarSigns - identifier contains $
41+
private String $internalValue;
42+
private int item$Count;
43+
44+
// Tier 1: Bad formatting - inconsistent spacing and indentation
45+
public TestClass(String value,int count){
46+
this.$internalValue=value;
47+
this.item$Count=count;
48+
}
49+
50+
// Tier 2 (Sorald S1155): Use isEmpty() instead of size() == 0
51+
public boolean isListEmpty(List<String> items) {
52+
// S1155: should use items.isEmpty() instead
53+
if (items.size() == 0) {
54+
return true;
55+
}
56+
return false;
57+
}
58+
59+
// Tier 2 (Sorald S1155): Another isEmpty pattern
60+
public boolean hasNoElements(ArrayList<Integer> numbers) {
61+
// S1155: should use numbers.isEmpty()
62+
return numbers.size() == 0;
63+
}
64+
65+
// Tier 2 (Sorald S1155): Map isEmpty check
66+
public boolean isMapPopulated(Map<String, Object> data) {
67+
// S1155: should use !data.isEmpty()
68+
if (data.size() != 0) {
69+
return true;
70+
}
71+
return false;
72+
}
73+
74+
// Tier 2 (Sorald S1132): String literals should be on left of equals
75+
public boolean checkStatus(String status) {
76+
// S1132: "active" should be on the left side
77+
if (status.equals("active")) {
78+
return true;
79+
}
80+
// S1132: "pending" should be on the left side
81+
if (status.equals("pending")) {
82+
return true;
83+
}
84+
return false;
85+
}
86+
87+
// Tier 3 (PMD): UselessParentheses - unnecessary parentheses
88+
public int calculate(int a, int b) {
89+
// PMD UselessParentheses: extra parentheses around expressions
90+
int result = ((a + b));
91+
int multiplied = ((result) * 2);
92+
int divided = (((a + b) / 2));
93+
return ((result + multiplied + divided));
94+
}
95+
96+
// Tier 3 (PMD): EmptyCatchBlock - catch block is empty
97+
public String readFileContent(String path) {
98+
String content = "";
99+
try {
100+
// Tier 2 (Sorald S2095): Resource should be in try-with-resources
101+
BufferedReader reader = new BufferedReader(new FileReader(path));
102+
String line;
103+
while ((line = reader.readLine()) != null) {
104+
content += line;
105+
}
106+
reader.close();
107+
} catch (IOException e) {
108+
// PMD EmptyCatchBlock: empty catch block - should log or rethrow
109+
}
110+
return content;
111+
}
112+
113+
// Tier 3 (PMD): CloseResource - resource not properly closed
114+
public byte[] readBytes(String filePath) {
115+
byte[] data = null;
116+
try {
117+
// PMD CloseResource: FileInputStream not closed properly
118+
FileInputStream fis = new FileInputStream(filePath);
119+
data = new byte[fis.available()];
120+
fis.read(data);
121+
// Missing: fis.close() or should use try-with-resources
122+
} catch (IOException e) {
123+
System.err.println("Error reading file: " + e.getMessage());
124+
}
125+
return data;
126+
}
127+
128+
// Tier 1: Bad formatting - poor brace placement and spacing
129+
public void badlyFormattedMethod(String input,int count,boolean flag){
130+
if(flag){
131+
for(int i=0;i<count;i++){
132+
System.out.println(input+":"+i);
133+
}
134+
}else{
135+
System.out.println("Flag is false");
136+
}
137+
}
138+
139+
// Tier 3 (PMD): Multiple UselessParentheses
140+
public boolean complexCondition(int x, int y, int z) {
141+
// PMD UselessParentheses: unnecessary parentheses in boolean expression
142+
if (((x > 0)) && ((y > 0)) || ((z < 0))) {
143+
return ((true));
144+
}
145+
return ((false));
146+
}
147+
148+
// Tier 2 (Sorald S2095): InputStream resource leak
149+
public int countLines(File file) {
150+
int lineCount = 0;
151+
try {
152+
// S2095: Should use try-with-resources
153+
InputStream is = new FileInputStream(file);
154+
BufferedReader reader = new BufferedReader(new java.io.InputStreamReader(is));
155+
while (reader.readLine() != null) {
156+
lineCount++;
157+
}
158+
// Resources not properly closed
159+
} catch (IOException e) {
160+
// PMD EmptyCatchBlock
161+
}
162+
return lineCount;
163+
}
164+
165+
// Tier 3 (PMD): AvoidDollarSigns in method parameters
166+
public void processData(String $data, int $count) {
167+
// PMD AvoidDollarSigns: parameter names contain $
168+
for (int $i = 0; $i < $count; $i++) {
169+
System.out.println($data);
170+
}
171+
}
172+
173+
// Tier 2 (Sorald S1132): Multiple equals comparisons with string literals
174+
public String categorize(String input) {
175+
// S1132: All string comparisons have literal on wrong side
176+
if (input.equals("category_a")) {
177+
return "A";
178+
} else if (input.equals("category_b")) {
179+
return "B";
180+
} else if (input.equals("category_c")) {
181+
return "C";
182+
}
183+
return "Unknown";
184+
}
185+
186+
// Tier 1: Bad formatting - inconsistent indentation and spacing
187+
public List<String> filterList(List<String>items,String prefix){
188+
List<String>result=new ArrayList<>();
189+
for(String item:items){
190+
if(item.startsWith(prefix)){
191+
result.add(item);
192+
}
193+
}
194+
return result;
195+
}
196+
197+
// Tier 2 (Sorald S1155): Collection size check in loop condition
198+
public void processItems(List<String> items) {
199+
// S1155: should use !items.isEmpty() instead of items.size() > 0
200+
while (items.size() > 0) {
201+
String item = items.remove(0);
202+
System.out.println("Processing: " + item);
203+
}
204+
}
205+
206+
// Tier 3 (PMD): Combined issues - UselessParentheses and poor formatting
207+
public int computeScore(int base,int bonus,int penalty){
208+
int score=((base+bonus)-penalty);
209+
if(((score)<0)){
210+
score=((0));
211+
}
212+
return ((score));
213+
}
214+
215+
// Tier 3 (PMD): Empty catch block with resource issues
216+
public Map<String, String> loadProperties(String path) {
217+
Map<String, String> props = new HashMap<>();
218+
try {
219+
// PMD CloseResource + S2095: FileInputStream not in try-with-resources
220+
FileInputStream fis = new FileInputStream(path);
221+
java.util.Properties p = new java.util.Properties();
222+
p.load(fis);
223+
for (String name : p.stringPropertyNames()) {
224+
props.put(name, p.getProperty(name));
225+
}
226+
} catch (IOException e) {
227+
// PMD EmptyCatchBlock: should handle or log exception
228+
}
229+
return props;
230+
}
231+
232+
// Getter with bad formatting
233+
public String get$InternalValue(){return this.$internalValue;}
234+
235+
// Setter with bad formatting
236+
public void set$InternalValue(String value){this.$internalValue=value;}
237+
238+
// Getter for item count with dollar sign
239+
public int getItem$Count(){return this.item$Count;}
240+
}

rex-progress.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,3 +592,12 @@ Commit: [main d8b8fed2] rex(#2): Create Live Test Fixture - Python
592592
create mode 100644 packages/agents/src/fix-agent/__tests__/fixtures/live-test-python.py
593593
d8b8fed2
594594

595+
596+
=== Task #3 (2026-01-19 10:39:29) ===
597+
Title: Create Live Test Fixture - TypeScript
598+
Status: COMPLETE
599+
Commit: [main 18063e5c] rex(#3): Create Live Test Fixture - TypeScript
600+
3 files changed, 245 insertions(+), 4 deletions(-)
601+
create mode 100644 packages/agents/src/fix-agent/__tests__/fixtures/live-test-typescript.ts
602+
18063e5c
603+

rex-tasks.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"source": "docs/rex-session-106-live-integration.md",
33
"createdAt": "2026-01-19T18:00:00Z",
44
"maxIterations": 30,
5-
"currentIteration": 3,
5+
"currentIteration": 4,
66
"status": "ready",
77
"validation": {
88
"type": "live-integration",
@@ -69,11 +69,11 @@
6969
"packages/agents/src/fix-agent/__tests__/fixtures/live-test-typescript.ts"
7070
],
7171
"priority": "high",
72-
"passes": false,
72+
"passes": true,
7373
"attempts": 0,
7474
"lastError": null,
75-
"completedAt": null,
76-
"commitHash": null
75+
"completedAt": "2026-01-19T15:39:29Z",
76+
"commitHash": "[main 18063e5c] rex(#3): Create Live Test Fixture - TypeScript\n 3 files changed, 245 insertions(+), 4 deletions(-)\n create mode 100644 packages/agents/src/fix-agent/__tests__/fixtures/live-test-typescript.ts\n18063e5c"
7777
},
7878
{
7979
"id": 4,

0 commit comments

Comments
 (0)