Skip to content

Commit

Permalink
Handle the error if the icon is not loadable (#6344). (#6944)
Browse files Browse the repository at this point in the history
  • Loading branch information
torok-peter authored and Denis committed Nov 22, 2019
1 parent 90d4411 commit a04435e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
14 changes: 10 additions & 4 deletions flow-server/src/main/java/com/vaadin/flow/server/PwaRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@
import java.util.List;
import java.util.stream.Collectors;

import com.vaadin.flow.server.frontend.FrontendUtils;
import com.vaadin.flow.server.startup.ApplicationRouteRegistry;

import elemental.json.Json;
import elemental.json.JsonArray;
import elemental.json.JsonObject;
import org.slf4j.LoggerFactory;

/**
* Registry for PWA data.
Expand Down Expand Up @@ -90,11 +92,15 @@ private PwaRegistry(PWA pwa, ServletContext servletContext)
// fall back to local image if unavailable
BufferedImage baseImage = getBaseImage(logo);

// Pick top-left pixel as fill color if needed for image resizing
int bgColor = baseImage.getRGB(0, 0);
if (baseImage == null) {
LoggerFactory.getLogger(PwaRegistry.class).error("Image is not found or can't be loaded: " + logo);
} else {
// Pick top-left pixel as fill color if needed for image resizing
int bgColor = baseImage.getRGB(0, 0);

// initialize icons
icons = initializeIcons(baseImage, bgColor);
// initialize icons
icons = initializeIcons(baseImage, bgColor);
}

// Load offline page as string, from servlet context if
// available, fall back to default page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.misc.ui.MiscelaneousView.MyTheme;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.server.PWA;
import com.vaadin.flow.theme.AbstractTheme;
import com.vaadin.flow.theme.Theme;

Expand All @@ -31,8 +32,11 @@

//`src/` in component above should be replaced by `theme/my-theme`
@Theme(MyTheme.class)
@PWA(name = "Project Base for Vaadin", shortName = "Project Base")
public class MiscelaneousView extends Div {


public static final String TEST_VIEW_ID = "MiscellaneousView";

public static class MyTheme implements AbstractTheme {
@Override
public String getBaseUrl() {
Expand All @@ -46,5 +50,6 @@ public String getThemeUrl() {
}

public MiscelaneousView() {
setId(TEST_VIEW_ID);
}
}
1 change: 1 addition & 0 deletions flow-tests/test-misc/src/main/webapp/icons/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,19 @@ public void should_loadThemedComponent_fromLocal() {
WebElement body = findElement(By.tagName("body"));
Assert.assertEquals("2px", body.getCssValue("padding"));
}

/**
* Checks that a missing or incorrect icon is handled properly with an
* error log and does not halt the whole application startup.
*/
@Test
public void handlesIncorrectIconProperly() {
open();

checkLogsForErrors();

Assert.assertTrue(
"Missing/invalid icons at startup should be handled with error log.",
isElementPresent(By.id(MiscelaneousView.TEST_VIEW_ID)));
}
}

0 comments on commit a04435e

Please sign in to comment.