Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
1 vote
1 answer
199 views

Spring MVC controller

My code has a nasty smell that looks like this: ...
dwjohnston's user avatar
  • 1,298
3 votes
2 answers
239 views

Throw exception in Spring when loading a file

I have this following piece of code: ...
Manuelarte's user avatar
1 vote
1 answer
495 views

Reading files and displaying their content

I'm writing a program to read two files supplied as arguments in the command line, convert them from list to char[][], and display their contents to the user. I'm trying to practice exception-...
kevinlelo's user avatar
3 votes
1 answer
428 views

Varnish - HttpClient Exception Handling

I'm consuming some messages from a rabbit queue. Within the consumer/processor I need to invalidate a varnish cache and requeue the message if the purge failed. I'm using a local purge proxy. The ...
Gabe's user avatar
  • 131
5 votes
1 answer
271 views

Transferring data from one file stream to another

I am currently reading Clean Code and for fun and profit, I intended to refactor some of the Java Tutorials and since I wanted to improve my Exception handling, the Byte Stream one with its lots of ...
AdHominem's user avatar
  • 728
3 votes
1 answer
660 views

Using a Boolean method that never returns "false" to check user permissions

I need to check that a user is allowed to save/retrieve contacts to/from the database by calling a web service, and return an HTTP403 with an explanation if it is not the case. So for the sake of ...
Anas's user avatar
  • 143
2 votes
1 answer
1k views

Retrieving access token from SharedPreference

Here is code that retrieves an access token from SharedPreference. ...
Vsevolod Poletaev's user avatar
2 votes
2 answers
220 views

RSS to JSON for insertion into MongoDB

In my code, there is a chain of functions call where the deepest function may throw an exception. I catch and handle it according to the business logic. The problem is that all other functions in the ...
Mike's user avatar
  • 277
1 vote
1 answer
139 views

Recording a customer's shopping cart as an order 2.0

Some days ago, I put up a question here for review about the best way to handle JDBC transactions in the context of an e-commerce Java web application. After a kind suggestion from user @gardenhead, ...
Enrique's user avatar
  • 145
2 votes
2 answers
279 views

Recording a customer's shopping cart as an order

I have come up with the following method to post a transaction to a database, in the context of an e-commerce Java web application. The transaction consists in submitting a new order alongside its ...
Enrique's user avatar
  • 145
7 votes
2 answers
301 views

Querying Facebook for details of a user's OAuth token

This class exposes the public method getAuthToken which takes a user's Facebook OAuth token as an input parameter and queries Facebook for information about it - ...
sav0h's user avatar
  • 73
6 votes
2 answers
5k views

Single class which holds response and error message

I am working on a library which will make HTTP call to my rest service basis on inputs passed to this library. And whatever response comes back from service whether it is successful response or ...
david's user avatar
  • 1,947
3 votes
0 answers
369 views

Stylishly saving source

Simple tool to save a web page's source. A result of trying to learn and apply an MVC approach. The FXML is generated via Scene Builder, but included for completion. I welcome any general feedback on ...
Legato's user avatar
  • 9,839
3 votes
1 answer
3k views

Retry Runnable java

I want to make class to retry doing what I want if specific exception happen for n times before throwing exception, so I write below class and used Builder to build it could you please review it and ...
Bassem Reda Zohdy's user avatar
4 votes
2 answers
94 views

Delay to avoid cocurrent modification

I was attempting to remove items from an ArrayList while iterating through it, only to find out that Java doesn't like that. So I quickly wrote up a ...
ndm13's user avatar
  • 718
33 votes
6 answers
4k views

Unbreakable average program

I'm creating a program that averages four numbers - three from a file and one from user input. Simple enough. But the catch is, the professor is going to be deliberately trying to break the program. ...
PsylentKnight's user avatar
5 votes
1 answer
6k views

Layered architecture implementation in a Java web application

I am trying to learn how to design and implement a layered Java web application with a presentation layer, service layer and the DAO layer. I have used the Struts 1.3 framework with Java JDK 1.6 for ...
Shiva's user avatar
  • 151
6 votes
2 answers
1k views

Servlet file uploader

I think this code looks ugly, especially with the multiple try-catch blocks, but I don't know how to rewrite it: ...
gstackoverflow's user avatar
4 votes
2 answers
262 views

Property file loader

I have the following code: ...
Eugene Ustimenko's user avatar
4 votes
2 answers
94 views

Printing gitignores

I have written a simple program in Java 7 to write the .gitignore of different file types: ...
CodeYogi's user avatar
  • 5,127
0 votes
1 answer
1k views

JUnit test case to check that an exception of type javax.mail.MessagingException is not thrown

I have a method which will send a text mail using JavaMail API and I am trying to write a test case for this method which will check if an Exception of type ...
Sandeep Chatterjee's user avatar
3 votes
1 answer
1k views

Catch all checked exceptions and turn into unchecked exception

I am currently trying to learn Lambdas and following the book Java SE8 for the really Impatient and just finished Chapter 1 of it. This is the question, I am trying to get done with: Didn’t you ...
SSC's user avatar
  • 501
5 votes
1 answer
6k views

Handling an invalid SQL query exception

This is my DAO object that takes the Cypher query as a string, and returns a JSON representation of the graph it returns. Because it's using a Spring JdbcTemplate ...
dwjohnston's user avatar
  • 1,298
3 votes
1 answer
22k views

Checking for Internet connectivity on Android

I wrote this code to check an internet connection and was wondering if this is the best way to do this check. ...
Mina Fawzy's user avatar
7 votes
1 answer
787 views

Proper checked exception handling with lambda functions

I'm having trouble finding a clean way to handle checked exceptions thrown by a lambda function passed as a parameter in Java. I'm writing a Client which will interact via RMI with a Server to play a ...
gcali's user avatar
  • 203
5 votes
5 answers
4k views

Map error messages to conditions

I have a method which checks some preconditions and if everything is fine returns a success response object, otherwise fail with ...
vtor's user avatar
  • 225
5 votes
2 answers
16k views

IO and Scanner exception handling

I have created a sample file reading program as an exercise while learning how to implement good exception handling. I want to ask: is this a good approach or is there some other solution that I am ...
Deepak Singh's user avatar
0 votes
1 answer
267 views

Asking for a number in Java Swing

Is it good way of asking for a number? Should that function return 0 if there is an error? ...
siema's user avatar
  • 117
3 votes
1 answer
3k views

Functionality for automatic retry after exception

I have made the following system to automatically retry network calls if some exception is thrown. (Earlier posted on stackOverFlow, solution inspired by what @Boris answered) ...
Dexter's user avatar
  • 415
4 votes
1 answer
196 views

String find and replace method optimization

I am trying to find a specific header string from different Maps (LEDES1998Bheaders, LEDES98BIheaders and ...
OTUser's user avatar
  • 747
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 <...
david's user avatar
  • 1,947
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 ...
david's user avatar
  • 1,947
2 votes
1 answer
264 views

Logging of various exceptions in the callback

I am working on a library in which I need to execute my URL using AsyncRestTemplate and after that I will get a json response back if it is successful. I am also making ...
david's user avatar
  • 1,947
3 votes
1 answer
49 views

Deciding whether an anchor should be updated

A colleague and I were discussing the following code today and had a disagreement over the return false in the ...
Stuart Leyland-Cole's user avatar
0 votes
2 answers
123 views

Searching for an account by accountId

I have a piece of code that is fetching account objects from a service ...
Anand Sunderraman's user avatar
1 vote
1 answer
114 views

Logging errors with the same exception type

I wrote some code which simply retrieves the HTTP status code of the passed in URL. There are multiple potential causes of the same error. I am hoping to get some all around feedback on this code, ...
Evorlor's user avatar
  • 524
4 votes
2 answers
283 views

Verifying value before parsing

I am writing some Java code and am coming across a try/catch block in which I decided to verify the value is not null before parsing it: ...
Vince's user avatar
  • 275
-2 votes
1 answer
957 views

Retrying to read a file [closed]

I have a piece code which retries 3 more times to open a file (see below). Are there potential problems or side effects with the way it is written? How can it be improved? Also, why would one use <...
Qrious's user avatar
  • 7
3 votes
1 answer
398 views

Servlet responses to upload/download requests

My task is to write a program to store files in object store. One of the subtasks requires to send json or xml format response to the file uploader/downloader as requested by client. The following ...
gkiko's user avatar
  • 131
9 votes
3 answers
457 views

Exception handling and general check in Java

Are the catch statements ok or must I put in a println()? In general, is the code good-looking enough? ...
Highlights Factory's user avatar
0 votes
2 answers
23k views

Extract data from database and write them to file

I wanted to write a program that performed a query to a database, then formatted the data before writing it to a file. I thus created 4 classes, which are: a main class a class dealing with the ...
l0r3nz4cc10's user avatar
4 votes
0 answers
629 views

Exception logger for servlets and JSPs

I hate using unnecessary catch blocks and I like to see my code look beautiful. In most of the cases in my project, which is a web application, I can't declare many ...
phoenix's user avatar
  • 277
4 votes
1 answer
170 views

Do you view this ThrowingFunction interface as "interface abuse"?

I am currently implementing a fun project involving lambdas and this project makes heavy use of the ability of Java 8 to have default methods in interfaces. But when does such "heavy use" turn into ...
fge's user avatar
  • 1,733
4 votes
2 answers
11k views

Multi threaded TCP server

I wrote this just for fun, to hone my exception handling skills. I want to know what I can do better in terms of exception handling (and otherwise) in the below code Server ...
Parth Mehta's user avatar
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? ...
KirdApe's user avatar
  • 95
5 votes
1 answer
6k views

AsyncTask which allows to handle exceptions on UI

The AsyncTask available in android, gives you the result from doInBackground on the UI thread so that you can update UI ...
Ammar's user avatar
  • 431
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 ...
k_rollo's user avatar
  • 478
3 votes
2 answers
74k views

Class design for a student class

Problem Statement: Design a STUDENT class to store roll, name, course, admission date and marks in 5 subjects taken from user. Create an array of STUDENT objects. Provide methods ...
SouvikMaji's user avatar
4 votes
1 answer
2k views

Error Handling in Servlets and JSPs

I have an HTML login form that is processed by a servlet, which then redirects the user to a result page. login.jsp: ...
k_rollo's user avatar
  • 478
5 votes
3 answers
5k views

User registration Servlet

I have a servlet that processes user registration to a website. It takes inputs from an HTML form like username, password, email, etc. MySQL Table: ...
k_rollo's user avatar
  • 478