All Questions
Tagged with error-handling java
156 questions
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 ...
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 ...
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 ...
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 ...
7
votes
1
answer
693
views
Pausing a SwingWorker with a Timer
I made a SwingWorker which is fetching tweets using the twitter4j API.
The twitter API will allow 180 queries every 15 minutes, and then throw an exception with ...
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 ...
7
votes
1
answer
337
views
Calling other machines from the LinkedList if one is blocked or down
This is a follow on to : Simplifying asynchronous "executeAsync" method along with "onFailure" callback.
I am using AsyncRestTemplate as my <...
5
votes
2
answers
100
views
Proper action when a Java program fails
I have a program that has to initialize a few big things (connect to a few databases, parse some XML) and without the initialization being successful the program would not be able to continue.
Right ...
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 ...
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 ...
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 ...
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 ...
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 ...
8
votes
3
answers
2k
views
Simplifying asynchronous "executeAsync" method along with "onFailure" callback
I have a system in which user id is "sharded" across all the machines which means each machine is responsible for certain user id data. I am working on a library which will take ...
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 ...
1
vote
1
answer
178
views
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 ...
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 ...
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 ...
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. ...
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 ...
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:
...
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 ...
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 ...
3
votes
2
answers
162
views
JSON fetcher for Eclipse plugin
This is a client module of an Eclipse plugin. I am planning to use this code as a "good exception handling" code example in one of my papers. How does it look?
...
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?
...
8
votes
3
answers
53k
views
HttpURLConnection response code handling
This snippet from a downloader callable handles HTTP status codes. I need critique on both the style (for or do-while loop ...
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 ...
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 ...
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 ...
14
votes
4
answers
64k
views
Checking if a port is in use
Review this code, which should return true if a port is in use or false if the port is not in use.
Clarification: "In use" ...
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, ...
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 ...
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 ...
1
vote
1
answer
72
views
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 ...
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 ...
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 ...
2
votes
1
answer
1k
views
Retry Class in Java
I have the following Java code used to retry a certain actions/methods
...
1
vote
2
answers
7k
views
Servlet and JSP for user registration, with CAPTCHA and error handling
I have a form that submits to a registration Servlet, which inserts a new user to the database when they sign up to the web application. Depending on the erroneous user input, the Servlet will ...
6
votes
5
answers
9k
views
Java Stream Exception Handling
I find this piece of Java code really ugly and cumbersome. How can I refactor it to be more clean and easier to read?
...
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 ...
7
votes
1
answer
4k
views
Reducing cyclomatic complexity
I ran a sonar analysis on my code and it told me the cyclomatic complexity is too high (sonar's limit is ten branches).
Here is my code:
...
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, ...
6
votes
2
answers
3k
views
Setter error checking
I have a class called Duration which has the attributes hours, mins, and ...
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 ...
3
votes
2
answers
239
views
Throw exception in Spring when loading a file
I have this following piece of code:
...
1
vote
1
answer
1k
views
1
vote
1
answer
1k
views
utility class for reading in JSON
I'm reasonably happy with the execution:
...
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:
...