Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
4 votes
2 answers
941 views

Simple load balancer

I would like to know the possible improvements in design and concurrency of the following load balancer: ability to add/register new instance keep max of 10 instances for load balancer forbid ...
tinyzero4's user avatar
0 votes
1 answer
186 views

Handling exceptions of FileInputStream and XSSFWorkbook

Can you tear my code apart with code review comments? Below is a simple method which reads an XLSX file and does some stuff with it. I use FileInputStream and ...
AutoTester999's user avatar
1 vote
1 answer
161 views

Beginner Java Tic-Tac-Toe

I had a Tic Tac Toe assignment for class and the program seems to work fine but I feel like the exception/input handling could be done in a much better way. Is this a good way to approach the ...
Drosos-kal's user avatar
3 votes
2 answers
128 views

Spring boot shop application with error handling

I'm writing a simple online shop using spring boot, for learning purposes. Right now I have purchasing-service and a product-service. The purchasing-service makes requests to the product-service via ...
Eoin's user avatar
  • 263
0 votes
1 answer
62 views

When to use IllegalStateException [closed]

I am implementing an API that implements an interface, but I do not need to implement all methods. In that case, is it better to just return null or throw an IllegalStateException because it if not ...
Neslihan Bozer's user avatar
1 vote
1 answer
3k views

Spring boot: better way to handle response and exceptions

I am working on a quite a big Spring Boot web service and I wanted a standardized and simplified way to handle responses and exceptions by following fluent API design. So this is what I did and it ...
benjamin c's user avatar
5 votes
0 answers
1k views

Exception handling: using @JsonProperty value to make error message

If the validation in RestController fails, I need to handle MethodArgumentNotValidException and provide an errorMessage, that ...
Georgii Lvov's user avatar
1 vote
1 answer
885 views

Android APP FTP uploading file implementation in Java

This is a follow-up question for Android APP FTP host profile class implementation and Android APP connect to FTP server in Java. I am attempting to perform the upload operation to specified FTP ...
JimmyHu's user avatar
  • 5,510
1 vote
1 answer
63 views

Android APP user registration page implementation

This is a follow-up question for Android APP User class implementation. I am attempting to build a user registering system and this post shows the user registration page implementation. The ...
JimmyHu's user avatar
  • 5,510
1 vote
1 answer
77 views

Android APP Password Strength Assessment class implementation

This is a follow-up question for Android APP User class implementation. I am attempting to create a password strength assessment class which is named ...
JimmyHu's user avatar
  • 5,510
1 vote
1 answer
1k views

Read and sort 100 numbers from a text file

The program itself reads 100 values from a text file named input.txt. Then sorts those values in ascending order and writes the values to a new file called ...
HunterShaw's user avatar
1 vote
1 answer
178 views

In Spring framework, should the controller let the client know that something went wrong by returning a response entity with the proper error code?

Category Service: ...
Alexandros Kourtis's user avatar
2 votes
0 answers
393 views

Custom MediaController with full screen video image option

I have overridden setAnchorView() of MediaController class to display full screen option icon using below code.The code seems to be working fine in devices I tested but I have few doubts for which I ...
Android Developer's user avatar
3 votes
2 answers
324 views

Tic-Tac-Toe in Java

I am currently learning Java; I could really use some help from more experienced programmers. How can I clean up my Tic-Tac-Toe code? What mistakes have I made? Can I use more exception handling? I ...
Xaver Csibri's user avatar
2 votes
1 answer
83 views

Code for adding a user to the database

I have a code that adds a user to the database, getting the username from the dialog.My fragment implements the interface with the onInputSend method, which is called by the dialog when the user ...
Destroyer's user avatar
  • 459
4 votes
2 answers
238 views

Reader for graph-file with ugly return and questionable use of streams

I wrote a class that contains a static method that reads in files from NetworkRepository and converts them into a list of integer-arrays, each representing an edge. The file format from ...
Moritz Groß's user avatar
3 votes
1 answer
332 views

Java: Only log first error occurrence (with hourly reset)

I have a redis caching server. If that caching server is down, my app will query the database directly. I want to know from the logs if my caching server is not reachable. However, if I add a log ...
TeaCup's user avatar
  • 181
2 votes
2 answers
1k views

Beginning BMI calculator in Java

This is my first program so no doubt I've made mistakes. The code works and meets all requirements as far as I can see. (Further info: program to calculate Body Mass Index (BMI) allowing user to ...
Julie Cohen's user avatar
3 votes
1 answer
526 views

Poor error handling: Throw inside Finally

I have the following code which I am running through fortify. Why it gets marked for poor error handling, throw inside finally? ...
Karan Khanna's user avatar
2 votes
2 answers
692 views

Jsoup connection to URL

I have simple class that I want to ask if is there any possible to improve it? I mean, for me it looks poor. Is there any way to use here try-with-resources, stream or ...
mara122's user avatar
  • 183
5 votes
2 answers
2k views

Thread-safe stack in Java with fixed capacity

Implement a multi-threaded stack, with freedom to use existing implementations of stack. On top of being thread-safe, it must block (not busy-wait) a pushing thread when stack is full and a ...
user5447339's user avatar
2 votes
2 answers
163 views

Validating that a Java program has two equal-length arguments

I'm writing a small almost one method Java class for a job application and the advice given was to write it as though it was a piece of commercial software. The ...
Joel Biffin's user avatar
5 votes
3 answers
1k views

A more functional try...catch construct in Java

I saw a question on Stack Overflow asking for a review of a custom try...catch construct that made use of Optionals, and got the idea to try writing my own version. ...
Carcigenicate's user avatar
0 votes
2 answers
48 views

Printing the status of a database insertion as JSON

The controller is currently inserting a record into the database and returning a JSON response as shown below in the try-catch block. I can see the ...
John's user avatar
  • 195
2 votes
1 answer
48 views

Testing a probabilistic prime-testing algorithm that may fail

I have implemented Pollard's Rho algorithm in Java. Due to the nature of it there is a small chance for it to fail (have not seen it happening yet). Since I do not ...
Navarro's user avatar
  • 165
1 vote
1 answer
72 views

Exception handling with null check in java

...
Hyeonseo Yang's user avatar
0 votes
1 answer
66 views

Logging util with static lambda function

So again, I am a bit confused about some notes that i'am getting from my reviewer. I have some kind of utils, to print/prepare log messages. Yea, maybe I am a bit fanatic java 8 lambda guy but I think ...
shutdown -h now's user avatar
3 votes
1 answer
413 views

Given a list of words, remove the shorter word of every pair

This is not a "please do my homework" question. I solved a problem two ways and would like to know which solution is better; better being defined by better readability, lower complexity and lower ...
npengra317's user avatar
1 vote
1 answer
158 views

Spring API that performs RSA encryption with exception handling [closed]

I'm creating a rest api using Spring which utilize javax.crypto as library to do some encryption stuff. While everything works well, I'm curious whether the error handling like this is acceptable or ...
imeluntuk's user avatar
  • 223
2 votes
1 answer
1k views

Retry Class in Java

I have the following Java code used to retry a certain actions/methods ...
MoonKnight's user avatar
2 votes
0 answers
66 views

Catching exceptions arised by different senarios and handle them differently [closed]

I am learning exception handling in java. Every time I am writing a function, I wonder if I should put the entire function code in a try catch block. What the function does: In the below function, i ...
rehas's user avatar
  • 21
4 votes
1 answer
196 views

Given a sorted (increasing order) array, write an algorithm to create a binary tree with minimal height

I'm trying to find the complexity of this code and some suggestions for improving the code quality. and handling the code gracefully, esp in the areas of exception handling, checking edge cases, ...
user2769790's user avatar
6 votes
2 answers
3k views

Setter error checking

I have a class called Duration which has the attributes hours, mins, and ...
Brett Warren's user avatar
1 vote
1 answer
1k views

NullPointer Exception handling in the code [closed]

...
wandermonk's user avatar
1 vote
1 answer
1k views

utility class for reading in JSON

I'm reasonably happy with the execution: ...
Thufir's user avatar
  • 369
1 vote
5 answers
8k views

Exception handling calculate power

I've to create a class MyCalculator which consists of a single method long power(int, int). This method takes two integers, and, as parameters and finds Math.pow(n,p). - If either n or p is negative, ...
user2769790's user avatar
2 votes
1 answer
397 views

Is catching null pointer exception to handle it instead of null check beforehand always a bad practice or it depends? [closed]

I wrote a static method for an enum that returns the corresponding enum instance based on the source string, trimming any whitespaces and ignoring case as: ...
Vikas Prasad's user avatar
2 votes
1 answer
2k views

Spring MVC @ControllerAdvice exception handling

This is about handling sql - foreign key constraint failure exceptions (SQL Error: 1452, SQLState: 23000) globally using ...
benjamin c's user avatar
1 vote
1 answer
199 views

Is it a valid use case of using java.util.MissingResourceException?

I have a factory method that returns an Object based on a argument passed to it : ...
Innocuous's user avatar
0 votes
1 answer
294 views

Refactoring code to throw a single exception per function [closed]

One of my functions must throws 2 exceptions, but I understand 1 exception per function is preferred (at least according to my client's Sonar ruleset). Can you ...
Joe Essey's user avatar
  • 119
0 votes
3 answers
92 views

Processing an InputStream and writing to an OuputStream, and ensuring that both streams get closed

Is it a bad thing to do multiple file closings in single finally block? Relevant excerpt: ...
industryworker3595112's user avatar
1 vote
2 answers
78 views

Reinitialize cache periodically, catching and logging any Throwables

My existing code has a scheduler that we init when a DataStore constructor is called. ...
Naman's user avatar
  • 111
5 votes
2 answers
745 views

Send records and retry them if acknowledgement is not received

I am working on a project where I need to consume lot of records and then I am sending these records to some other system which uses zeromq. Here is the flow: Store all the incoming records in a CHM ...
david's user avatar
  • 1,947
2 votes
1 answer
175 views

Filtering out the correct car from a list of cars and retrieving only one car

I am filtering out a List<Car> based on the brand. Since each car is made by one brand, I want to make sure my method ...
OPK's user avatar
  • 285
5 votes
2 answers
312 views

URL decode a string but log an error after second exception

I have a method which does URL decoding on the string value passed along with using Charset: ...
user5447339's user avatar
4 votes
1 answer
184 views

Validating attributes of a page in Adobe Experience Manager

I am reviewing the following code written by a fellow developer. I am not an java expert but IMHO i did not feel this is efficient use of exceptions — the reason I feel so is: The below code throwing ...
Dennis's user avatar
  • 41
1 vote
1 answer
932 views

Job queue with threading

On many articles and blogs, I have read that exceptions should not decide flow of your code. I have wrote the following code using one thread: ...
Bhushan's user avatar
  • 113
0 votes
1 answer
67 views

SQL message logger run loop

I am learning Java by reading source code of other authors. This Java method handles communication with SQL database. While the code does work several things concern me. For instance the ...
sixtytrees's user avatar
3 votes
1 answer
123 views

Command sequence executor with error handling

I've recently learned that as a Java developer my methods throw exceptions way too often, even when the reason for throwing is related to a business rule, when returning an error code instead could ...
Piovezan's user avatar
  • 257
2 votes
4 answers
1k views

Throwing exceptions if there is not exactly one box retrieved

(Note: this is originally posted as this SO question ) I'm trying to refactor the error logging and exception throwing into a method. Original code: ...
XoXo's user avatar
  • 185